![simple email program for python simple email program for python](https://linuxhint.com/wp-content/uploads/2019/11/2-9.png)
Print("Connection from: " + str(address)) # configure how many client the server can listen simultaneouslyĬonn, address = server_socket.accept() # accept new connection Server_socket.bind((host, port)) # bind host address and port together
![simple email program for python simple email program for python](https://miro.medium.com/max/858/0*IPQ2XhwQXNDA62Pe.jpg)
The bind() function takes tuple as argument Server_socket = socket.socket() # get instance Port = 5000 # initiate port no above 1024 See the below python socket server example code, the comments will help you to understand the code. It is recommended to user port address above 1024 because port number lesser than 1024 are reserved for standard internet protocol. We can obtain host address by using socket.gethostname() function. Then, sequentially we need to perform some task to establish connection between server and client. To use python socket connection, we need to import socket module.
![simple email program for python simple email program for python](https://www.mssqltips.com/tipimages2/6520_python-program-design.004.png)
We will save python socket server program as socket_server.py. Server program will also terminate when client program terminates, this is optional and we can keep server program running indefinitely or terminate with some specific command in client request. Client program will terminate if user enters “bye” message.Then server program will response accordingly to client requests.Python socket client program will initiate the conversation at first.Python socket server program executes at first and wait for any request.So we will design both server and client model so that each can communicate with them. We have said earlier that a socket client requests for some resources to the socket server and the server responds to that request.