Computer Network 2
Computer Network 2
9.
10.
11.
12.
13.
14.
15.
Experiment No: 3
Date:
TECHNICAL OBJECTIVE:
To implement FTP application, where the Client on establishing a connection with the Server
sends the name of the file it wishes to access remotely. The Server then sends the contents of the
file to the Client, where it is stored.
METHODOLOGY:
Server:
while True:
conn, addr = s.accept() # Establish connection with client.
print 'Got connection from', addr
data = conn.recv(1024)
print('Server received', repr(data))
filename='mytext.txt'
f = open(filename,'rb')
l = f.read(1024)
while (l):
conn.send(l)
print('Sent ',repr(l))
l = f.read(1024)
f.close()
print('Done sending')
conn.send('Thank you for connecting')
conn.close()
CLIENT
# client.py
import socket # Import socket module
s.connect((host, port))
s.send("Hello server!")
f.close()
print('Successfully get the file')
s.close()
print('connection closed')
OUTPUT
INFERENCE:
Thus, the FTP client-server communication is established and data is transferred between the
client and server machine
Experiment No: 4
Date:
TECHNICAL OBJECTIVE:
import socket
localIP = "127.0.0.1"
localPort = 20001
bufferSize = 1024
msgFromServer = "Hello UDP Client"
bytesToSend = str.encode(msgFromServer)
msgFromServer = UDPClientSocket.recvfrom(bufferSize)
INFERENCE:
Thus, the UDP ECHO client server communication is established by sending the message from
the client to the server and server prints it and echoes the message back to the client.
Experiment No: 5
Date:
TECHNICAL OBJECTIVE:
Domain Name Server (DNS) is implemented through this program. The web address of any
website is given by the Client as the input. The DNS Server looks up for the corresponding
domain and returns the IP address as the output.
METHODOLOGY:
CODE:
SERVER
# server.py
import socket
dns_table={"www.google.com": "192.165.1.1","www.youtube.com":
"192.165.1.2","www.gmail.com": "192.165.1.3"}
print("starting server.. .")
while True:
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.bind(("127.0.0.1",1234))
data,address=s.recvfrom(1024)
print(f"{address} wants to fetch data")
data=data.decode()
ip=dns_table.get(data,"not found").encode()
send=s.sendto(ip,address)
s.close()
CLIENT
# client.py
import socket
hostname=socket.gethostname()
addr=("127.0.0.1",1234)
c = "Y"
while c.upper()=="Y":
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
req_domain = input("enter domain name for which the ip is needed:")
send=s.sendto(req_domain.encode(),addr)
data, address=s.recvfrom(1024)
reply_ip = data.decode().strip()
print(f"the ip for the domain name{req_domain}:{reply_ip}")
c=(input("continue?(y/n)"))
s.close()
OUTPUT
INFERENCE:
Thus the DNS Server is developed to get the domain name from the remote machine and to send
the IP address of the domain as response from server’s DNS table.