COMPUTER NETWORKS ASSIGNMENT
JYOTHI T
1. Write client/server socket programs using TCP for any
requirement.
Client side –
from socket import *
port = 12345
client_socket = socket(AF_INET, SOCK_STREAM)
client_socket.connect(('127.0.0.1', port))
message = "Hello, this is the jyothi"
client_socket.send(message.encode())
print("Message sent to server:", message)
client_socket.close()
Server side –
from socket import *
port = 12345
server_socket = socket(AF_INET,SOCK_STREAM)
server_socket.bind(('127.0.0.1', port))
server_socket.listen(1)
print('Server is listening:')
while True:
client_socket, address = server_socket.accept()
message = client_socket.recv(1024).decode()
print("Message from client:", message)
client_socket.close()
server_socket.close()
Server code execution
Client code execution
Wireshark output
2. Write client and server socket programs using UDP for any
requirement.
Client side –
from socket import *
port = 12345
client_socket = socket(AF_INET, SOCK_DGRAM)
number = raw_input('Enter a number: ')
client_socket.sendto(number.encode(), ('127.0.0.1', port))
print('Number sent to server:', number)
square, server_address = client_socket.recvfrom(1024)
print('Square received from server:', square.decode())
client_socket.close()
Server side –
from socket import *
port = 12345
server_socket = socket(AF_INET, SOCK_DGRAM)
server_socket.bind(('127.0.0.1', port))
print('Server is listening on-')
while True:
message, client_address = server_socket.recvfrom(1024)
number = int(message.decode())
square = number ** 2
server_socket.sendto(str(square).encode(), client_address)
Run server code
Run Client code-
Wireshark output -
3.Usage of ping and netstat in networks
Ping –
Ping works by sending an Internet Control Message Protocol (ICMP)
Echo Request to a specified interface on the network and waiting for
a reply. When a ping command is issued, a ping signal is sent to a
specified address. When the target host receives the echo request, it
responds by sending an echo reply packet.
Eg: ping youtube.com
Netstat –
The netstat command is used to show network status.
Traditionally, it is used more for problem determination than for
performance measurement. However, the netstat command can be
used to determine the amount of traffic on the network to ascertain
whether performance problems are due to network congestion.
The netstat command displays information regarding traffic on the
configured network interfaces, such as the following:
The address of any protocol control blocks associated with the
sockets and the state of all sockets
The number of packets received, transmitted, and dropped in
the communications subsystem
Cumulative statistics per interface
Routes and their status
Example : netstat -a