Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to create a simple server using socket module in python?

Description

To create a simple server using socket programming in python3.

Process

   Import socket library.

   Create socket object s.

   Define the port number(5 digits).

   Bind the port and socket object using s.bind().

  Check socket has been created or not.

   Server listening if any connection from client using s.listen().

   If connection available accept the client using s.accept().

   Then stop the server.

Sample Code

#import socket module
import socket

#create socket object
s = socket.socket()
print(“Socket created successfully”)
port = 54546
#Bind the port
s.bind((”, port))

#check the socket binded to the port
print(“socket binded to “,(port))
s.listen(5)
print(“server listening”)
while True:

#accept the connection
c, addr=(s.accept())

#send status message to the client
c.send(‘connected’)

#Terminate the connection
c.close()

Screenshots
create a simple server using socket module in python