Function |
Describe |
S.bind () |
Bind an address to a socket, and the address in the form of a tuple (host,port) under Af_inet |
S.listen () |
Start TCP snooping. The backlog specifies the maximum number of connections that the operating system can suspend before rejecting the connection. This value is at least 1 |
S.accept () |
Passively accepts TCP client connections, (blocking) waits for a connection to arrive |
S.connect () |
Active initialization of TCP server connection, general address format is tuple (hostname,port), if connection error, return socket.error error |
S.RECV () |
Receives TCP data, the data is returned as a string, bufsize specifies the maximum amount of data to receive, and flag provides additional information about the message |
S.send () |
Sends the TCP data to the connected socket by sending the data in the string. The return value is the number of bytes to send, which may be less than the byte size of the string |
S.sendall () |
Sends the TCP data in full, sends the data in the string to the connected socket, attempts to send all data before returning, succeeds, returns none, throws an exception if failed |
S.recvfrom () |
The UDP data is received, similar to recv (), but the return value is (data,address). Where data is the string that contains the received information, and address is the socket that sends the data |
S.sendto () |
Send UDP data, send data to a socket, address is a tuple in the form of (Ipaddr,port), specify a remote address, and the return value is the number of bytes sent. |
S.close () |
Close socket |
S.getpeername () |
Returns the remote address of the connection socket, which is typically a tuple (ipaddr,port). |
S.getsockname () |
Returns the socket's own address |
S.setsockopt (Level,optname,value) |
Sets the value of a given socket option |
S.getsockopt (Level,optname,[,buflen]) |
Returns the value of the socket option |
S.settimeout (Timeout) |
Sets the timeout period for the socket operation, and timeout is a floating-point number in seconds. A value of None indicates no over-time. In general, hyper-times should be set when a socket is just created, as they may be used for connected operations |
S.gettimeout () |
Returns the value in seconds for the current timeout period. Returns none if no timeout period is set |
S.fineno () |
Returns the file descriptor of a socket |
S.setblocking (flag) |
If flag is 0, the socket is set to non-blocking mode, otherwise the socket is set to blocking mode (the default value). In nonblocking mode, if the call recv () does not find any data, or the Send () call cannot send the data immediately, the SOCKET.ERROR exception is caused |
S.makefile () |
Create a file associated with the socket |