The socket Module (cont)

socket methods

     s.accept()                # Accept a new connection
     s.bind(address)           # Bind to an address and port
     s.close()                 # Close the socket
     s.connect(address)        # Connect to remote socket
     s.fileno()                # Return integer file descriptor
     s.getpeername()           # Get name of remote machine
     s.getsockname()           # Get socket address as (ipaddr,port)
     s.getsockopt(...)         # Get socket options
     s.listen(backlog)         # Start listening for connections
     s.makefile(mode)          # Turn socket into a file object
     s.recv(bufsize)           # Receive data
     s.recvfrom(bufsize)       # Receive data (UDP)
     s.send(string)            # Send data
     s.sendto(string, address) # Send packet (UDP)
     s.setblocking(flag)       # Set blocking or nonblocking mode
     s.setsockopt(...)         # Set socket options
     s.shutdown(how)           # Shutdown one or both halves of connection

Comments

  • There are a huge variety of configuration/connection options.
  • You'll definitely want a good reference at your side.
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 90
July 17, 2000, beazley@cs.uchicago.edu
>>>