Skip to content

Commit 730d892

Browse files
committed
Add TCP server support(EN_API)
1 parent 2aa8bea commit 730d892

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

en-us/api/pythonStdlib.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,8 +1199,8 @@ type - socket type
11991199
proto - protocol number
12001200

12011201
* usocket.IPPROTO_TCP
1202-
12031202
* usocket.IPPROTO_UDP
1203+
* usocket.IPPROTO_TCP_SER : socket for TCP Server
12041204

12051205
Others
12061206

@@ -1216,6 +1216,8 @@ import usocket
12161216
socket = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
12171217
# Creating UDP-based Datagram Sockets
12181218
socket = usocket.socket(usocket.AF_INET, usocket.SOCK_DGRAM)
1219+
# Creating TCP-based server sockets
1220+
socket = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM, usocket.IPPROTO_TCP_SER)
12191221
```
12201222

12211223
##### Translate the host/port argument into a sequence of 5-tuples
@@ -1230,6 +1232,25 @@ Translate the host/port argument into a sequence of 5-tuples. The resulting list
12301232

12311233
#### Class Socket Methods
12321234

1235+
##### Bind specified address
1236+
1237+
> **socket.bind(address)**
1238+
1239+
Bind the socket to address. The socket must not already be bound. (The format of address depends on the address family)
1240+
1241+
* `address` : A tuple or list containing addresses and port numbers
1242+
1243+
Example:
1244+
1245+
```
1246+
# Bind the datacall IP to the server address
1247+
socket.bind(("",80))
1248+
# Bind a custom IP to the server address
1249+
socket.bind(("192.168.0.1",80))
1250+
```
1251+
1252+
#####
1253+
12331254
##### Enable a server to accept connections
12341255

12351256

@@ -1243,7 +1264,7 @@ Enable a server to accept connections. The maximum number of connections can be
12431264

12441265
> **socket.accept()**
12451266
1246-
Accept a connection and return a tuple. The socket must be bound to an address and listening for connections. The return value is a pair `(conn, address)`
1267+
Accept a connection and return a tuple. The socket must be bound to an address&port and listening for connections. The return value is a pair `(conn, address, port)`
12471268

12481269
* `conn` : new socket object usable to send and receive data on the connection
12491270

@@ -1399,6 +1420,8 @@ Get socket status. The status values are described as follows:
13991420

14001421
Note:
14011422

1423+
The BG95 platform does not support this API.
1424+
14021425
If the user calls the ` socket.getsocketsta () ` after calling the ` socket.close () ` method, it returns-1 because the object resources and so on created at this point have been freed.
14031426

14041427
**Socket Communication Example**

0 commit comments

Comments
 (0)