myhost 'myport get socket constructor and constants 'all available interfaces on host listen on non-reserved port number sockobj socket(af_inetsock_streamsockobj bind((myhostmyport)sockobj listen( make tcp socket object bind it to server port number listenallow pending connects while trueconnectionaddress sockobj accept(print('server connected by'addresswhile truedata connection recv( if not databreak connection send( 'echo=>dataconnection close(listen until process killed wait for next client connect connection is new socket read next line on client socket send reply line to the client until eof when socket closed as mentioned earlierwe usually call programs like this that listen for incoming connections servers because they provide service that can be accessed at given machine and port on the internet programs that connect to such server to access its service are generally called clients example - shows simple client implemented in python example - pp \internet\sockets\echo-client py ""client sideuse sockets to send data to the serverand print server' reply to each message line'localhostmeans that the server is running on the same machine as the clientwhich lets us test client and server on one machineto test over the internetrun server on remote machineand set serverhost or argv[ to machine' domain name or ip addrpython sockets are portable bsd socket interfacewith object methods for the standard socket calls available in the system' library""import sys from socket import serverhost 'localhostserverport portable socket interface plus constants server nameor'starship python netnon-reserved port used by the server message [ 'hello network world'default text to send to server requires bytesb'or str,encode(if len(sys argv serverhost sys argv[ server from cmd line arg if len(sys argv text from cmd line args message ( encode(for in sys argv[ :]sockobj socket(af_inetsock_streamsockobj connect((serverhostserverport)make tcp/ip socket object connect to server machine port for line in messagesockobj send(linedata sockobj recv( print('client received:'datasend line to server over socket receive line from serverup to bytes are quotedwas ` `repr(xsockobj close(close socket to send eof to server socket programming