To know how to connect fb using python socket programming using python3.
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.
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()