socket.recv

socket.recv(bufsize, flag)

  • This function receives data from a socket
  • This refers to a client or server receiving data from the other
  • The bufsize limits how much data can be received
  • For example, socket.recv(1024) will read at most 1024 bytes
  • It will block I/O if no data has arrived

Example of recv

>>> import socket

>>> sock = socket(AF_INET, SOCK_STREAM)
>>> address = ('', 25000)
>>> sock.bind(address)

>>> client, ad = sock.accept()
>>> data = client.recv(100)
>>> print(data)
'hello world'  # client sent 'hello world' beforehand

References

Previous
Next

socket.makefile

socket.recvfrom