• Home
Name Date Size #Lines LOC

..--

entry/12-May-2024-1,4201,337

screenshots/devices/12-May-2024-

.gitignoreD12-May-2024121 88

README.mdD12-May-20241.9 KiB3819

README_zh.mdD12-May-20241.8 KiB3619

build-profile.json5D12-May-20241 KiB4341

hvigorfile.jsD12-May-2024174 21

package.jsonD12-May-2024369 1818

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

README_zh.md

1# 网络管理-Socket连接
2
3### 简介
4
5本示例主要演示了Socket在网络通信方面的应用,展示了Socket在两端设备的连接验证、聊天通信方面的应用。实现效果如下:
6
7![](screenshots/devices/chats.png)
8
9### 相关概念
10
11UDP Socket是面向非连接的协议,它不与对方建立连接,而是直接把我要发的数据报发给对方,适用于一次传输数据量很少、对可靠性要求不高的或对实时性要求高的应用场景。
12
13### 相关权限
14
15网络权限: ohos.permission.INTERNET
16获取WIFI信息的权限: ohos.permission.GET_WIFI_INFO
17
18### 使用说明
19
201.打开应用,点击**用户**文本框选择要登录的用户,并输入另一个设备的IP地址,点击**确定**按钮进入已登录的用户页面(两个设备都要依次执行此步骤)。
21
222.在其中一个设备上点击**创建房间**按钮,任意输入房间号,另一个设备会收到有房间号信息的弹框,点击**确定**按钮后,两个设备进入聊天页面。
23
243.在其中一个设备上输入聊天信息并点击**发送**按钮后,另一个设备的聊天页面会收到该聊天消息。
25
264.点击顶部标题栏右侧的**退出**图标按钮,则返回已登录的用户页面。
27
285.点击聊天页面中的昵称栏,会弹出一个菜单,选择离线选项后,两端设备的状态图标都会切换为离线图标,并且昵称栏都会变成灰色,此时任何一端发送消息另一端都接收不到消息。
29
306.当点击昵称栏再次切换为在线状态,则两端的己方账号状态会切换为在线图标,同时两端的昵称栏会显示蓝色,此时可正常收发消息。
31
32### 约束与限制
33
341.本示例仅支持在标准系统上运行。
35
362.本示例需要使用DevEco Studio 3.0 Beta4 (Build Version: 3.0.0.992, built on July 14, 2022)才可编译运行。