نمای کلی
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
Nearby Connections یک API شبکه همتا به همتا است که به برنامهها اجازه میدهد بدون در نظر گرفتن اتصال به شبکه، به راحتی دادهها را در زمان واقعی پیدا کنند، به آن متصل شوند و با دستگاههای مجاور مبادله کنند.
چند نمونه از موارد استفاده:
- تخته سفید مشارکتی: ایده ها را با شرکت کنندگان در نزدیکی روی تخته سفید مجازی مشترک یادداشت کنید.
- بازی چند نفره محلی: یک بازی چند نفره راهاندازی کنید و از سایر کاربران اطراف دعوت کنید تا به آن بپیوندند.
- بازی چند صفحهای: از تلفن یا رایانه لوحی بهعنوان کنترلکننده بازی برای اجرای بازیهای نمایش داده شده در دستگاه اندرویدی با صفحهنمایش بزرگ، مانند Android TV، استفاده کنید.
- انتقال فایل آفلاین: عکس ها، ویدیوها یا هر نوع داده دیگری را به سرعت و بدون نیاز به اتصال شبکه به اشتراک بگذارید.
مقدمه
Nearby Connections تبلیغات، کشف و ارتباط بین دستگاههای اطراف را به صورت کاملاً آفلاین امکانپذیر میکند. اتصالات بین دستگاهها با پهنای باند بالا، تأخیر کم و کاملاً رمزگذاری شدهاند تا امکان انتقال سریع و ایمن دادهها را فراهم کنند.
هدف اصلی این API ارائه یک پلتفرم ساده، قابل اعتماد و کارآمد است. API از ترکیبی از فناوریهای بلوتوث، BLE و Wi-Fi استفاده میکند و از نقاط قوت هر یک استفاده میکند و در عین حال نقاط ضعف مربوطه را دور میزند. این به طور موثری ابهامات بلوتوث و وای فای را در طیف وسیعی از پلتفرمها و نسخههای سیستمعامل انتزاعی میکند و به توسعهدهندگان این امکان را میدهد تا روی ویژگیهایی که برای کاربرانشان مهم است تمرکز کنند.
نمای کلی API
استفاده از API به دو مرحله تقسیم می شود: قبل از اتصال و پس از اتصال.
در مرحله قبل از اتصال، تبلیغکنندگان خودشان را تبلیغ میکنند، در حالی که کشفکنندگان آگهیدهندگان نزدیک را کشف میکنند و درخواستهای اتصال را ارسال میکنند. درخواست اتصال از کشف کننده به تبلیغ کننده، یک جریان احراز هویت متقارن را آغاز می کند که منجر به پذیرش (یا رد کردن) درخواست اتصال از سوی هر دو طرف می شود.
پس از پذیرش درخواست اتصال توسط دو طرف، اتصال برقرار شده در نظر گرفته می شود و دستگاه ها وارد مرحله پس از اتصال می شوند که طی آن دو طرف می توانند داده ها را مبادله کنند.
تبلیغات و کشف
تبلیغکنندگان برای سایر اکتشافات قابل مشاهده خواهند بود و زمانی که تبلیغکننده جدیدی پیدا شد یا گم شد، به کاشفان اطلاع داده میشود.
ایجاد ارتباطات
زمانی که کاشف میخواهد به تبلیغکننده نزدیک متصل شود، کاشف میتواند درخواست اتصال کند.
هر دو طرف از روند شروع اتصال مطلع خواهند شد و هر دو این فرصت را خواهند داشت که اتصال را بپذیرند یا رد کنند.
هنگامی که هر دو طرف پاسخ دادند، نتیجه به هر یک اطلاع داده می شود. اگر هر دو طرف اتصال را پذیرفتند، اتصال برقرار شده در نظر گرفته می شود و انتقال داده می تواند آغاز شود.
تبادل داده ها
پس از برقراری ارتباط، استفاده بیشتر از API متقارن است، بنابراین دیگر تمایزی بین Advertiser و Discoverer وجود ندارد.
اکنون هر دو طرف می توانند داده ها را مبادله کنند. 3 نوع Payloads پشتیبانی شده وجود دارد:
- بایت ها: آرایه های بایت محدود به 32k; این ها برای ارسال چیزهایی مانند فراداده یا پیام های کنترلی خوب هستند.
- فایل: فایل با هر اندازه. اینها با حداقل کپی در مرزهای فرآیند از برنامه به رابط شبکه منتقل می شوند.
- جریان: جریانی از دادهها که در جریان تولید میشوند، مانند موارد صوتی/تصویری ضبطشده، بدون اندازه نهایی از قبل.
دریافت کنندگان از داده های دریافتی جدید و هرگونه به روز رسانی پیشرفت، لغو یا شکست مطلع خواهند شد.
اتصالات ایجاد شده تمام دوبلکس هستند، به این معنی که تبلیغ کنندگان و کاشفان می توانند به طور همزمان داده ها را ارسال و دریافت کنند.
جمع آوری داده ها
هنگام استفاده از سرویسهای Google Play Nearby SDK، تجزیه و تحلیل استفاده برای بهبود تجربه جمعآوری میشود.
- معیارهای عملکرد: تأخیر کشف و اتصال، قابلیت اطمینان و توان عملیاتی هنگام اسکن و اتصال به دستگاهها با استفاده از Nearby SDK جمعآوری میشوند.
- اطلاعات دستگاه: مدل دستگاه، کشور، نسخه ساخت و نام بسته برنامه جمعآوری شده و با معیارهای عملکرد مرتبط میشوند تا بخشهای منطقهای و دستگاه خاص شناسایی شوند.
کاربران نهایی میتوانند با رفتن به تنظیمات > Google > استفاده و عیبیابی، این مجموعه را مجاز یا رد کنند.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-13 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-08-13 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eNearby Connections is a peer-to-peer networking API enabling apps to discover, connect, and exchange data with nearby devices in real-time, even without internet access.\u003c/p\u003e\n"],["\u003cp\u003eIt leverages Bluetooth, BLE, and Wi-Fi for high-bandwidth, low-latency, and encrypted communication, abstracting away the complexities of these technologies.\u003c/p\u003e\n"],["\u003cp\u003eThe API facilitates advertising, discovery, and connection establishment between devices, followed by data exchange using bytes, files, or streams.\u003c/p\u003e\n"],["\u003cp\u003eUsage analytics, including performance metrics and device information, are collected to enhance the API's performance but can be controlled by users in their device settings.\u003c/p\u003e\n"]]],[],null,["# Overview\n\nNearby Connections is a peer-to-peer networking API that allows apps to easily\ndiscover, connect to, and exchange data with nearby devices in real-time,\nregardless of network connectivity.\n\nSome example use cases:\n\n- **Collaborative whiteboard:** Jot ideas down with nearby participants on a shared virtual whiteboard.\n- **Local multiplayer gaming:** Set up a multiplayer game and invite other users nearby to join.\n- **Multi-screen gaming:** Use a phone or tablet as a game controller to play games displayed on a nearby large-screen Android device, such as Android TV.\n- **Offline file transfers:** Share photos, videos, or any other type of data quickly and without requiring a network connection.\n\nIntroduction\n------------\n\nNearby Connections enables advertising, discovery, and connections between\nnearby devices in a fully-offline peer-to-peer manner. Connections between\ndevices are high-bandwidth, low-latency, and fully encrypted to enable fast,\nsecure data transfers.\n\nA primary goal of this API is to provide a platform that is simple, reliable,\nand performant. Under the hood, the API uses a combination of Bluetooth, BLE,\nand Wi-Fi technologies, leveraging the strengths of each while circumventing\ntheir respective weaknesses. This effectively abstracts the vagaries of\nBluetooth and Wi-Fi across a range of platforms and OS versions, allowing\ndevelopers to focus on the features that matter to their users.\n\nAPI overview\n------------\n\nUsage of the API falls into two phases: pre-connection, and post-connection.\n\nIn the pre-connection phase, Advertisers advertise themselves, while Discoverers\ndiscover nearby Advertisers and send connection requests. A connection request\nfrom a Discoverer to an Advertiser initiates a symmetric authentication flow\nthat results in both sides independently accepting (or rejecting) the connection\nrequest.\n\nAfter a connection request is accepted by both sides, the connection is\nconsidered to be established and the devices enter the post-connection phase,\nduring which both sides can exchange data.\n\n### Advertising and discovery\n\nAdvertisers will become visible to other discovers and discoverers will be\nnotified when a new advertiser is found or has been lost.\n\n### Establishing connections\n\nWhen a discoverer wishes to connect to a nearby advertiser, the discoverer can\nrequest a connection.\n\nBoth sides will be notified of the connection initiation process and both will\nhave the opportunity to accept or reject the connection.\n\nOnce both sides have responded, each will be notified of the result. If both\nsides accepted the connection, the connection is considered established, and\ndata transference can then begin.\n\n### Exchanging data\n\nAfter a connection is established, further API usage is symmetrical, so there's\nno longer a distinction between Advertiser and Discoverer.\n\nBoth sides can now exchange data. There are 3 types of supported Payloads:\n\n- **Bytes:** Byte arrays limited to 32k; these are good for sending things such as metadata or control messages.\n- **File:** Files of any size; these are transferred from the app to the network interface with minimal copying across process boundaries.\n- **Stream:** A stream of data that is generated on the fly, as in the case of recorded audio/video, with no final size known beforehand.\n\nReceivers will be notified of new incoming data and any progress updates,\ncancellations or failures.\n\nThe connections established are full-duplex, which means that advertisers and\ndiscoverers can simultaneously send and receive data.\n\n### Data Collection\n\nWhen using the Google Play services Nearby SDK, usage analytics are collected to\nimprove the experience.\n\n- **Performance metrics:** Discovery and connection latency, reliability and throughput are collected when scanning for and connecting to devices using the Nearby SDK.\n- **Device information:** Device model, country, build version and the application package name are collected and associated with the performance metrics to identify regional and device-specific slices.\n\nEnd users can allow or deny this collection by navigating to Settings \\\u003e Google \\\u003e\nUsage \\& diagnostics."]]