Server socket methods

The following are some server socket methods, which are also shown in the following code:

  • bind(): With this method, we can define in which port our server will be listening to connections
  • listen(backlog): This method makes the socket accept connections and accept to start listening to connections
  • accept(): This method is used for accepting the following connection:
import socket

serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#bind the socket to localhost on port 80
serversocket.bind((‘localhost', 80))
#become a server socket and listen a maximum of 10 connections
serversocket.listen(10)
..................Content has been hidden....................

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