socket.sendall(data)
- This function sends data to a connected socket
- This function differs from
sendby blocking I/O until all thedatais sent - This refers to a client or server sending data to the other
- The
datarepresents the data sent - The
dataneeds to be a string - For example,
socket.sendall('hello')will send'hello'to a server socket - This function returns the number
nof bytes sent to the server - The
nmay be lower thanlen(data)if these is no space in the server socket's buffet - It will block I/O until space appears
Example of sendall
>>> import socket
>>> sock = socket(AF_INET, SOCK_STREAM)
>>> # connect with server at ip
>>> # address 32.21.671.11 on port 25000
>>> address = ('32.21.671.11', 25000)
>>> sock.connect(address)
>>> sock.sendall('hello world') # send to serverReferences
Previous
Next