নিরাপদ সংযোগ API
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
একটি দূরবর্তী ডিভাইস আবিষ্কার করার পরে, handleIntent
ফাংশন বলা হয়, এবং এটি ক্লায়েন্টদের মধ্যে ডেটা পাস করা শুরু করার সময়। এই বিভাগে একটি সুরক্ষিত সংযোগ বজায় রাখার চারটি প্রয়োজনীয় পদক্ষেপ রয়েছে:
- একটি সংযোগ খুলছে
- সংযোগ গ্রহণ
- ডেটা পাঠানো এবং গ্রহণ করা
- সংযোগ বন্ধ করা হচ্ছে
একটি সংযোগ খুলুন
একটি দূরবর্তী ডিভাইস থেকে ডেটা গ্রহণ করার জন্য একটি সংযোগ খুলতে, পূর্বে প্রাপ্ত অংশগ্রহণকারী বস্তু ব্যবহার করুন এবং CHANNEL_NAME
নির্দিষ্ট করুন :
কোটলিন
participant
.openConnection(CHANNEL_HELLO)
.onFailure { /* handle failure */}
.getOrNull()
?.let { connection ->
connection.send("Hello, world".toByteArray(UTF_8)).onFailure { /* handle failure */}
}
জাভা
public void openConnection(Participant participant) {
Futures.addCallback(
participant.openConnectionFuture(CHANNEL_HELLO),
new FutureCallback<RemoteConnection>() {
@Override
public void onSuccess(RemoteConnection remoteConnection) {
// use remoteConnection object to pass data, e.g.:
sendDataToRemoteConnection(remoteConnection);
}
@Override
public void onFailure(Throwable t) {
// handle error opening a remote connection
}
},
mainExecutor);
}
private void sendDataToRemoteConnection(RemoteConnection remoteConnection) {
Futures.addCallback(
remoteConnection.sendFuture("Hello, world".getBytes()),
new FutureCallback<Void>() {
@Override
public void onSuccess(Void result) {
// data sent successfully
}
@Override
public void onFailure(Throwable t) {
// handle error
}
},
mainExecutor);
}
একটি সংযোগ গ্রহণ করুন, পাঠান/গ্রহণ করুন এবং বন্ধ করুন
নিরাপদ কানেকশনের জন্য ডেটা পাওয়ার আগে রিসিভিং ডিভাইসের ইনকামিং কানেকশন গ্রহণ করতে হবে। একটি দূরবর্তী সংযোগ গ্রহণ করতে, নিম্নলিখিত স্নিপেট ব্যবহার করুন:
কোটলিন
suspend fun acceptIncomingConnection(participant: Participant) {
val connection = participant.acceptConnection(CHANNEL_HELLO).getOrThrow()
connection.registerReceiver(
object : ConnectionReceiver {
override fun onMessageReceived(remoteConnection: RemoteConnection, payload: ByteArray) {
displayMessage(payload.toString(UTF_8))
}
override fun onConnectionClosed(
remoteConnection: RemoteConnection,
error: Throwable?,
reason: String?
) {
// handle connection closure
}
}
)
}
জাভা
public void acceptIncomingConnection(Participant participant) {
// Registers call back to accept incoming remote connection
Futures.addCallback(
participant.acceptConnectionFuture(CHANNEL_HELLO),
new FutureCallback<>() {
@Override
public void onSuccess(RemoteConnection result) {
receiveData(result);
}
@Override
public void onFailure(Throwable t) {
// handle connection error
}
},
mainExecutor);
}
private void receiveData(RemoteConnection remoteConnection) {
remoteConnection.registerReceiver(
new ConnectionReceiver() {
@Override
public void onMessageReceived(RemoteConnection remoteConnection, byte[] payload) {
displayMessage(new String(payload, UTF_8));
}
@Override
public void onConnectionClosed(
RemoteConnection remoteConnection,
@Nullable Throwable error,
@Nullable String reason) {
// handle connection closure
}
});
}
এই পৃষ্ঠার কন্টেন্ট ও কোডের নমুনাগুলি Content License-এ বর্ণিত লাইসেন্সের অধীনস্থ। Java এবং OpenJDK হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-07-29 UTC-তে শেষবার আপডেট করা হয়েছে।
[[["সহজে বোঝা যায়","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-07-29 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],null,["# Secure connection API\n\nAfter discovering a remote device, the `handleIntent` function is called, and\nit's time to start passing data between clients. This section covers the\nfour essential steps of maintaining a secure connection:\n\n- Opening a connection\n- Accepting the connection\n- Sending and receiving data\n- Closing the connection\n\nOpen a connection\n-----------------\n\nTo open a connection to receive data from a remote device, use the\npreviously received participant object and specify `CHANNEL_NAME`: \n\n### Kotlin\n\n```kotlin\nparticipant\n .openConnection(CHANNEL_HELLO)\n .onFailure { /* handle failure */}\n .getOrNull()\n ?.let { connection -\u003e\n connection.send(\"Hello, world\".toByteArray(UTF_8)).onFailure { /* handle failure */}\n }\n```\n\n### Java\n\n```java\npublic void openConnection(Participant participant) {\n Futures.addCallback(\n participant.openConnectionFuture(CHANNEL_HELLO),\n new FutureCallback\u003cRemoteConnection\u003e() {\n @Override\n public void onSuccess(RemoteConnection remoteConnection) {\n // use remoteConnection object to pass data, e.g.:\n sendDataToRemoteConnection(remoteConnection);\n }\n\n @Override\n public void onFailure(Throwable t) {\n // handle error opening a remote connection\n }\n },\n mainExecutor);\n}\n\nprivate void sendDataToRemoteConnection(RemoteConnection remoteConnection) {\n Futures.addCallback(\n remoteConnection.sendFuture(\"Hello, world\".getBytes()),\n new FutureCallback\u003cVoid\u003e() {\n @Override\n public void onSuccess(Void result) {\n // data sent successfully\n }\n\n @Override\n public void onFailure(Throwable t) {\n // handle error\n }\n },\n mainExecutor);\n}\n```\n\nAccept, send/receive, and close a connection\n--------------------------------------------\n\nSecure connections require the receiving device to accept incoming connections\nbefore receiving the data. To accept a remote connection, use the following\nsnippet: \n\n### Kotlin\n\n```kotlin\nsuspend fun acceptIncomingConnection(participant: Participant) {\n val connection = participant.acceptConnection(CHANNEL_HELLO).getOrThrow()\n connection.registerReceiver(\n object : ConnectionReceiver {\n override fun onMessageReceived(remoteConnection: RemoteConnection, payload: ByteArray) {\n displayMessage(payload.toString(UTF_8))\n }\n\n override fun onConnectionClosed(\n remoteConnection: RemoteConnection,\n error: Throwable?,\n reason: String?\n ) {\n // handle connection closure\n }\n }\n )\n}\n```\n\n### Java\n\n```java\npublic void acceptIncomingConnection(Participant participant) {\n // Registers call back to accept incoming remote connection\n Futures.addCallback(\n participant.acceptConnectionFuture(CHANNEL_HELLO),\n new FutureCallback\u003c\u003e() {\n @Override\n public void onSuccess(RemoteConnection result) {\n receiveData(result);\n }\n\n @Override\n public void onFailure(Throwable t) {\n // handle connection error\n }\n },\n mainExecutor);\n}\n\nprivate void receiveData(RemoteConnection remoteConnection) {\n remoteConnection.registerReceiver(\n new ConnectionReceiver() {\n @Override\n public void onMessageReceived(RemoteConnection remoteConnection, byte[] payload) {\n displayMessage(new String(payload, UTF_8));\n }\n\n @Override\n public void onConnectionClosed(\n RemoteConnection remoteConnection,\n @Nullable Throwable error,\n @Nullable String reason) {\n // handle connection closure\n }\n });\n}\n```"]]