Research breakthrough possible @S-Logix pro@slogix.in

Office Address

  • 2nd Floor, #7a, High School Road, Secretariat Colony Ambattur, Chennai-600053 (Landmark: SRM School) Tamil Nadu, India
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to create simple server-client program using socket programming in python?

Description

To know how to connect fb using python socket programming using python3.

Process

Import socket library.

Create socket object.

Use socket module methods bind()
,listen(),accept() and connect().

First start the server using
terminal(python3 server.py).

Then start the client by $
telnet local host port number.

Connect client with server.

Sample Code

Source code(server):

#import socket module
import socket

#create socket object
s = socket.socket()
print(“Socket created successfully”)
port = 12348

#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(b”Thanks for connecting”)

#Terminate the connection
c.close()

Source code(client):

#import socket library
import socket

#create socket object
s = socket.socket()

#declare a port
port = 12348

#make connection
s.connect((‘127.0.0.1’, port))
print (s.recv(10))

#close the connection
s.close()

Screenshots
create simple server-client program using socket programming in python
python socket programming using python3