Lines Matching refs:socket
5 The Socket Connection module allows an application to transmit data over a socket connection throug…
22 Applications transmit data over TCP, UDP, Multicast, or TLS socket connections. The main applicatio…
24 - Implementing data transmission over TCP socket or UDP socket connections
25 - Implementing data transmission over TCP socket server connections
26 - Implementing data transmission over multicast socket connections
27 - Implementing data transmission over local socket connections
28 - Implementing data transmission over local socket server connections
29 - Implementing encrypted data transmission over TLS socket connections
30 - Implementing encrypted data transmission over TLS socket server connections
34 …of APIs and example code, see [Socket Connection](../reference/apis-network-kit/js-apis-socket.md).
36 Socket connection functions are mainly implemented by the **socket** module. The following table de…
46 …t** events from the client. This API is supported only for TCP and local socket connections. …
47 … | Binds an IP address to a port, or binds the address of a local socket. …
49 | close() | Closes a socket connection. …
50 | getState() | Obtains the status of a socket connection. …
51 …ed IP address and port, or connects to a local socket. This API is supported only for TCP and loca…
52 | getRemoteAddress() | Obtains the peer address of the socket connection. This func…
53 | setExtraOptions() | Sets other properties of the socket connection. …
54 … | Obtains other properties of a socket connection. This API is supported only for loc…
55 … the specified multicast group. This API is supported only for multicast socket connections. …
56 … the specified multicast group. This API is supported only for multicast socket connections. …
57 …ve (TTL) for multicast packets. This API is supported only for multicast socket connections. …
58 … the TTL for multicast packets. This API is supported only for multicast socket connections. …
59 …ag for multicast communication. This API is supported only for multicast socket connections. |
60 …ag for multicast communication. This API is supported only for multicast socket connections. …
61 | on(type: 'message') | Subscribes to **message** events of a socket connection. …
62 | off(type: 'message') | Unsubscribes from **message** events of a socket connection.…
63 | on(type: 'close') | Subscribes to **close** events of a socket connection. …
64 | off(type: 'close') | Unsubscribes from **close** events of a socket connection. …
65 | on(type: 'error') | Subscribes to **error** events of a socket connection. …
66 | off(type: 'error') | Unsubscribes from **error** events of a socket connection. …
67 … | Subscribes to **listening** events of a socket connection. This API is supported only for UD…
68 …| Unsubscribes from **listening** events of a socket connection. This API is supported only for UD…
69 … | Subscribes to **message** events of a socket connection. This API is supported only for TCP and…
70 …nsubscribes from **message** events of a socket connection. This API is supported only for TCP and…
72 TLS socket connection functions are mainly provided by the **tls_socket** module. The following tab…
78 | close(type: 'error') | Closes a socket connection. …
83 | getRemoteAddress() | Obtains the peer address of the TLS socket connection. …
86 | getState() | Obtains the status of a TLS socket connection. …
87 | off(type: 'close') | Unsubscribes from **close** events of a TLS socket connection. …
88 | off(type: 'error') | Unsubscribes from **error** events of a TLS socket connection. …
89 | off(type: 'message') | Unsubscribes from **message** events of a TLS socket connection. …
90 | on(type: 'close') | Subscribes to **close** events of a TLS socket connection. …
91 | on(type: 'error') | Subscribes to **error** events of a TLS socket connection. …
92 | on(type: 'message') | Subscribes to **message** events of a TLS socket connection. …
94 | setExtraOptions() | Sets other properties of the TLS socket connection. …
98 …plementation is similar for UDP socket and TCP socket connections. The following uses data transmi…
100 1. Import the required **socket** module.
102 2. Create a TCP socket connection. A **TCPSocketConnction** object is returned.
112 7. Enable the TCP socket connection to be automatically closed after use.
115 import { socket } from '@kit.NetworkKit';
120 remoteInfo: socket.SocketRemoteInfo = {} as socket.SocketRemoteInfo;
122 // Create a TCP socket connection. A TCPSocket object is returned.
123 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
142 let ipAddress : socket.NetAddress = {} as socket.NetAddress;
156 let tcpConnect : socket.TCPConnectOptions = {} as socket.TCPConnectOptions;
162 let tcpSendOptions: socket.TCPSendOptions = {
175 // Enable the socket connection to be automatically closed after use. Then, unsubscribe from events…
190 The TCP socket server connection process is described as follows:
192 1. Import the required **socket** module.
193 2. Create a TCP socket server connection. A **TCPSocketServer** object is returned.
194 …l IP address and port, and listen for and accept TCP socket connections established over the socke…
202 import { socket } from '@kit.NetworkKit';
205 // Create a TCP socket server connection. A TCPSocketServer object is returned.
206 let tcpServer: socket.TCPSocketServer = socket.constructTCPSocketServerInstance();
209 let ipAddress : socket.NetAddress = {} as socket.NetAddress;
220 remoteInfo: socket.SocketRemoteInfo = {} as socket.SocketRemoteInfo;
223 tcpServer.on("connect", (client: socket.TCPSocketConnection) => {
243 let tcpSendOptions : socket.TCPSendOptions = {} as socket.TCPSendOptions;
273 1. Import the required **socket** module.
288 import { socket } from '@kit.NetworkKit';
291 let multicast: socket.MulticastSocket = socket.constructMulticastSocketInstance();
293 let addr : socket.NetAddress = {
309 remoteInfo: socket.SocketRemoteInfo = {} as socket.SocketRemoteInfo;
341 1. Import the required **socket** module.
347 4. Connect to server based on the specified address of the local socket file.
351 6. If the socket connection is no longer needed, unsubscribe from message events and close the conn…
354 import { socket } from '@kit.NetworkKit';
356 // Create a local socket connection. A LocalSocket object is returned.
357 let client: socket.LocalSocket = socket.constructLocalSocketInstance();
358 client.on('message', (value: socket.LocalSocketMessageInfo) => {
374 // Specify the address of local socket file to connect to the server.
376 let localAddress : socket.LocalAddress = {
379 let connectOpt: socket.LocalConnectOptions = {
383 let sendOpt: socket.LocalSendOptions = {
397 // If the socket connection is no longer needed, unsubscribe from message events and close the conn…
410 The local socket connection process on the server is described as follows:
412 1. Import the required **socket** module.
416 3. Bind the address of the local socket file.
418 4. Subscribe to **connect** events of the local socket client and other events (optional).
420 5. When the local socket client is connected, obtain the **LocalSocketConnection** object through t…
424 7. Send messages to the local socket client through the **LocalSocketConnection** object.
426 8. When the communication ends, close the local socket connection.
431 import { socket } from '@kit.NetworkKit';
433 // Create a local socket server connection. A LocalSocketServer object is returned.
434 let server: socket.LocalSocketServer = socket.constructLocalSocketServerInstance();
435 // Create and bind the local socket file testSocket for listening.
437 let listenAddr: socket.LocalAddress = {
447 server.on('connect', (connection: socket.LocalSocketConnection) => {
452 connection.on('message', (value: socket.LocalSocketMessageInfo) => {
467 let sendOpt : socket.LocalSendOptions = {
495 The TLS socket connection process on the client is described as follows:
497 1. Import the required **socket** module.
503 4. Create a TLS socket connection. A **TLSSocketConnection** object is returned.
509 7. Enable the TLS socket connection to be automatically closed after use.
512 import { socket } from '@kit.NetworkKit';
517 remoteInfo: socket.SocketRemoteInfo = {} as socket.SocketRemoteInfo;
519 // Create a TLS socket connection (for two-way authentication). A TLSSocketConnection object is ret…
520 let tlsTwoWay: socket.TLSSocket = socket.constructTLSSocketInstance();
540 let ipAddress : socket.NetAddress = {} as socket.NetAddress;
554 let tlsSecureOption : socket.TLSSecureOptions = {} as socket.TLSSecureOptions;
559 tlsSecureOption.protocols = [socket.Protocol.TLSv12];
564 let tlsTwoWayConnectOption : socket.TLSConnectOptions = {} as socket.TLSConnectOptions;
577 // Enable the socket connection to be automatically closed after use. Then, unsubscribe from events…
589 // Create a TLS socket connection (for one-way authentication). A TLSSocketConnection object is ret…
590 let tlsOneWay: socket.TLSSocket = socket.constructTLSSocketInstance(); // One way authentication
623 let tlsOneWaySecureOption : socket.TLSSecureOptions = {} as socket.TLSSecureOptions;
627 let tlsOneWayConnectOptions: socket.TLSConnectOptions = {} as socket.TLSConnectOptions;
638 // Enable the socket connection to be automatically closed after use. Then, unsubscribe from events…
653 The process of upgrading a TCP socket connection to a TLS socket connection is as follows:
655 1. Import the required **socket** module.
657 …CP socket connection. For details, see [Transmitting Data over TCP Socket or UDP Socket Connection…
659 3. After the TCP socket connection is established, use the **TCPSocket** object to create a TLS soc…
667 7. Enable the TLS socket connection to be automatically closed after use.
670 import { socket } from '@kit.NetworkKit';
675 remoteInfo: socket.SocketRemoteInfo = {} as socket.SocketRemoteInfo;
678 // Create a TCP socket connection. A TCPSocket object is returned.
679 let tcp: socket.TCPSocket = socket.constructTCPSocketInstance();
695 let ipAddress: socket.NetAddress = {} as socket.NetAddress;
709 let tcpConnect: socket.TCPConnectOptions = {} as socket.TCPConnectOptions;
720 // After TCP socket connection is established, upgrade it to a TLS socket connection.
721 let tlsTwoWay: socket.TLSSocket = socket.constructTLSSocketInstance(tcp);
744 let tlsSecureOption: socket.TLSSecureOptions = {} as socket.TLSSecureOptions;
749 tlsSecureOption.protocols = [socket.Protocol.TLSv12];
754 let tlsTwoWayConnectOption: socket.TLSConnectOptions = {} as socket.TLSConnectOptions;
760 // Establish a TLS socket connection.
764 …// Enable the socket connection to be automatically closed after use. Then, unsubscribe from event…
782 The TLS socket connection process on the server is described as follows:
784 1. Import the required **socket** module.
786 2. Start the service and bind the IP address and port number to set up a TLS socket connection. The…
790 …LSSocketConnection** object through the callback when the client initiates a TLS socket connection.
796 7. Close the TLS socket connection if it is no longer needed.
801 import { socket } from '@kit.NetworkKit';
804 let tlsServer: socket.TLSSocketServer = socket.constructTLSSocketServerInstance();
806 let netAddress: socket.NetAddress = {
811 let tlsSecureOptions: socket.TLSSecureOptions = {
816 protocols: socket.Protocol.TLSv12,
822 let tlsConnectOptions: socket.TLSConnectOptions = {
836 remoteInfo: socket.SocketRemoteInfo = {} as socket.SocketRemoteInfo;
849 tlsServer.on('connect', (client: socket.TLSSocketConnection) => {