![]() |
Basical TCP/UDP client-server problem - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Networking (https://python-forum.io/forum-12.html) +--- Thread: Basical TCP/UDP client-server problem (/thread-1875.html) |
Basical TCP/UDP client-server problem - maolow - Feb-01-2017 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: 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()) RE: Basical TCP/UDP client-server problem - Skaperen - Feb-03-2017 what other port are you seeing? maybe there is other traffic going on at the same time. RE: Basical TCP/UDP client-server problem - wavic - Feb-03-2017 At TCP when you say a client, the code is for server and server part holds the client code ![]() RE: Basical TCP/UDP client-server problem - Skaperen - Feb-04-2017 yeah, it does look like client and server are reversed under tcp. |