sockets in python tryprint('connection from'client_addresswhile truedata connection recv( decode(print('received'dataif datakey str(dataupper(response addresses[keyprint('sending data back to the client'responseconnection sendallresponse encode()elseprint('no more data from'client_addressbreak finallyconnection close(if __name__ ='__main__'main(the server in the above listing sets up the addresses to contain dictionary of the names and addresses it then waits for client to connect to it this is done by creating socket and binding it to specific port (in this case port usingprint('create the socket'sock socket socket(socket af_inetsocket sock_streamprint('bind the socket to the port'server_address (socket gethostname() the construction of the socket object is discussed in more detail in the next section next the server listens for connection from client note that the sock listen(method takes the value indicating that it will handle one connection at time an infinite loop is then set up to run the server when connection is made from clientboth the connection and the client address are made available while there is data available from the clientit is read using the recv function note that the data received from the client is assumed to be string this is then used as key to look the address up in the address dictionary