APP Assignment -1
Network Paradigm
IMAAD ZAFFAR KHAN
RA1811003010850
Sec F2
QUESTION 1:
Servercode
import socket
s=[Link]()
print("socket created")
host=[Link]()
port=6666
[Link]((host,port))
[Link](11)
print("waiting")
while True:
cl,addr=[Link]()
print("connected with client",addr)
command=input("enter command:")
[Link](bytes(command,'utf-8'))
[Link]()
output :servercode
socket created
waiting
connected with client ('[Link]', 57231)
enter command:vasanth
CLIENTCODE:
import socket
cl=[Link]()
host=[Link]()
port=6666
[Link]((host,port))
k=[Link](1024).decode()
print(k)
Client output:
vasanth
Question 2:
Servercode:
import socket
s=[Link]()
print("socket created")
host=[Link]()
port=6666
[Link]((host,port))
[Link](11)
print("waiting")
while True:
cl,addr=[Link]()
print("connected with client",addr)
k=[Link](1024).decode()
[Link](bytes([Link](),'utf-8'))
[Link]()
Serveroutput:
socket created
waiting
connected with client ('[Link]', 57809)
Clientcode:
import socket
cl=[Link]()
host=[Link]()
port=6666
[Link]((host,port))
nam=input("Enter the name:")
[Link](bytes(nam,'utf-8'))
m=[Link](1024).decode()
print("uppercase of it is:",m)
Clientoutput:
Enter the name:vasanth
uppercase of it is: VASANTH
Question 3:
ServerCode:
import socket
s=[Link]()
print("socket created")
host=[Link]()
port=6666
[Link]((host,port))
[Link](11)
print("waiting")
while True:
cl,addr=[Link]()
print("connected with client",addr)
k=[Link](1024).decode()
if(k=='PING' or k=='ping'):
m='SERVER: PONG'
else:
m='SERVER DROPPED'
[Link](bytes(m,'utf-8'))
[Link]()
Serveroutput:
socket created
waiting
connected with client ('[Link]', 58628)
connected with client ('[Link]', 58632)
Clientcode:
import socket
cl=[Link]()
host=[Link]()
port=6666
[Link]((host,port))
nam=input("Enter the message:")
[Link](bytes(nam,'utf-8'))
print("CLIENT:",nam)
p=[Link](1024).decode()
print(p)
Clientoutput:
Enter the message:ping
CLIENT: ping
SERVER: PONG
Question 4:
ServerCode:
import socket
from threading import Thread
def thread():
while True:
data = [Link](1024)
print('Client Request :' + [Link]())
if data == 'quit' or not data:
print("Server Exiting")
break
data = input('Server Response:')
[Link]([Link]())
host = [Link]()
port = 3333
s = [Link]()
[Link]((host,port))
[Link](5)
print("Waiting for clients...")
while True:
conn,addr = [Link]()
print("Connected by ", addr)
pr = Thread(target=thread)
[Link]()
[Link]()
Client1:
import socket
s = [Link]()
host = [Link]()
port = 3333
[Link]((host,port))
[Link](bytes('ram','utf-8'))
while True:
data = [Link](1024)
if data == 'quit' or not data:
print("Quiting")
break
else:
print("Server: ",[Link]())
msg = input("Client: ")
[Link]([Link]())
[Link]()
Client2:
import socket
s = [Link]()
host = [Link]()
port = 3333
[Link]((host,port))
[Link](bytes('ravi','utf-8'))
while True:
data = [Link](1024)
if data == 'quit' or not data:
print("Quiting")
break
else:
print("Server: ",[Link]())
msg = input("Client: ")
[Link]([Link]())
[Link]()
Client3:
import socket
s = [Link]()
host = [Link]()
port = 3333
[Link]((host,port))
[Link](bytes('rakesh','utf-8'))
while True:
data = [Link](1024)
if data == 'quit' or not data:
print("Quiting")
break
else:
print("Server: ",[Link]())
msg = input("Client: ")
[Link]([Link]())
[Link]()
OUTPUTS
1. Client and Server:
Question 2:
Question 3:
Question 4:
Client 1
Client 2
Client 3