Hi guys!
For an exam I have to code two simple client-server scripts in Python in order to study sockets and transport level protocols.
While they are runnin I have to run Wireshark and sniff the traffic, to study the segments
Basically, this is the code of the UDP part. It works and the message is received, but when I sniff the data, the segment isn't there and there's another port, why?
Client:
The same for TCP:
Client:
For an exam I have to code two simple client-server scripts in Python in order to study sockets and transport level protocols.
While they are runnin I have to run Wireshark and sniff the traffic, to study the segments
Basically, this is the code of the UDP part. It works and the message is received, but when I sniff the data, the segment isn't there and there's another port, why?
Client:
import socket HOST = "127.0.0.1" PORT = 33333 MSG = 'Prova protocollo UDP' s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.sendto(MSG.encode('utf-8'), (HOST, PORT))Server:
import socket PORT = 33333 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.bind(("", PORT)) print ("Attesa sulla porta: ", PORT) while 1: data, addr = s.recvfrom(1024) print (data.decode('utf-8'))--------------
The same for TCP:
Client:
import socket HOST = '' PORT = 36000 MSGRCVD = 'Messaggio ricevuto' with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.bind((HOST, PORT)) s.listen(1) conn, addr = s.accept() with conn: print ('Connesso a: ', addr) while 1: data = conn.recv(1024) print(data.decode()) if not data: break conn.sendall(MSGRCVD.encode())Server:
import socket HOST = "127.0.0.1" PORT = 36000 MSG = 'Prova protocollo TCP' with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect((HOST, PORT)) s.send(MSG.encode()) data = s.recv(1024) print("Ricevuto: ", data.decode())