Getting ready

The socket Python module exposes low-level C APIs for communication over a network using the BSD (short for Berkeley Software Distribution) socket interface.

This module includes the Socket class, which includes the main methods for managing the following tasks:

  • socket ([family [, type [, protocol]]]): Builds a socket using the following as arguments:
    • The family address, which can be AF_INET (default)AF_INET6, or AF_UNIX
    • The type socket, which can be SOCK_STREAM (default)SOCK_DGRAM, or perhaps one of the other "SOCK_" constants
    • The protocol number (that is usually zero)
  • gethostname(): Returns the current IP address of the machine.
  • accept ()Returns the following pair of values (conn and address), where conn is a socket type object (to send/receive data on the connection), while address is the address connected to the socket on the other end of the connection.
  • bind (address): Associates the socket with the address server.
This method historically accepted a couple of parameters for the AF_INET addresses instead of a single tuple. 
  • close (): Provides the option to clean up the connection once communication with the client is finished. The sockets are closed and collected by the garbage collector. 
  • connect (address): Connects a remote socket to an address. The address format depends on the family address.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.108.11