Professional Documents
Culture Documents
Implementation of Socket Programming and Client
Implementation of Socket Programming and Client
Server.py
import socket
T_PORT = 5000
TCP_IP = '127.0.0.1'
BUF_SIZE = 300
# create a socket object name 'k'
k = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
print("Socket is created")
k.bind((TCP_IP, T_PORT))
print ("socket binded to %s" %(T_PORT))
k.listen(1)
print ("socket is listening")
con, addr = k.accept()
print ('Connection Address is: ' , addr)
data = con.recv(BUF_SIZE).decode()
print ("Received data", data)
con.close()
Client.py
import socket
T_PORT = 5000
TCP_IP = '127.0.0.1'
BUF_SIZE = 1024
k.connect((TCP_IP, T_PORT))
k.send(MSG.encode())
k.close
output
Server Window
Socket is created
socket is listening