Name Date Size

..25-Oct-20244 KiB

.gitignoreH A D25-Oct-2024100

build-profile.json5H A D25-Oct-20241 KiB

entry/H25-Oct-20244 KiB

hvigor/H25-Oct-20244 KiB

hvigorfile.jsH A D25-Oct-2024174

hvigorwH A D25-Oct-20242.1 KiB

hvigorw.batH A D25-Oct-20242 KiB

oh-package.json5H A D25-Oct-2024812

README.mdH A D25-Oct-20241.9 KiB

README_zh.mdH A D25-Oct-20245.4 KiB

screenshots/devices/H25-Oct-20244 KiB

README.md

1#  Network Management - Socket
2
3### Introduction
4
5This sample demonstrates the application of Socket in network communications, including connection authentication and chat communication between two devices.
6
7![](screenshots/devices/chats.png)
8
9### Concepts
10
11UDP Socket is a connectionless protocol, which allows sending of datagrams to the peer without first establishing a connection. The protocol is applicable when a small amount of data is transmitted at a time and real-time performance takes precedence over reliability.
12
13### Required Permissions
14
151. Internet access permission: "ohos.permission.INTERNET"
16
172. Wi-Fi access permission: "ohos.permission.GET_WIFI_INFO"
18
19### Usage Guidelines
20
211. Start the application, tap **User** to select your user ID, enter the IP address of the peer device, and click **confirm**. (Perform this step on both devices.)
22 
232. On one device, tap **create room** and enter a room number. On the other device, a dialog box containing the room number is displayed. Click **confirm**. The two devices enter the chat screen.
24
253. After entering a message on one device, tap **send message**. The message will be displayed on the chat page on the peer device.
26
274. Tap the **exit** icon on the right of the title bar to return to the login user page.
28
295. Tap the nickname bar on the chat screen, and select **offline** on the displayed menu. The icons of the two devices will change to the offline state, and the nickname bar turns gray. In this case, one device cannot receive messages from the peer device.
30
316. When you tap the nickname bar to switch to the online state, the icons of the two devices will change to the online state, and the nickname bar is displayed in blue. In this case, one device can receive messages from the peer device.
32
33### Constraints
34
351. This sample can only be run on standard-system devices.
36
372. This sample requires DevEco Studio 3.0 Beta4 (Build Version: 3.0.0.992, built on July 14, 2022) to compile and run.
38