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:
Server:
--------------
The same for TCP:
Client:
Server:
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:
1 2 3 4 5 6 |
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)) |
1 2 3 4 5 6 7 8 |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
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()) |
1 2 3 4 5 6 7 8 9 10 11 |
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()) |