Python Forum
Basical TCP/UDP client-server problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basical TCP/UDP client-server problem
#1
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())

Reply


Messages In This Thread
Basical TCP/UDP client-server problem - by maolow - Feb-01-2017, 10:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Paramiko Server -- Exception (server): Error reading SSH protocol banner ujlain 3 4,649 Jul-24-2023, 06:52 AM
Last Post: Gribouillis
  Asyncio | Websockets - general problem starting the server dreamer 5 3,286 Oct-26-2022, 11:55 AM
Last Post: dreamer
  Client/Server proper finalizing transfer wolfman5874 1 1,475 Jul-04-2022, 07:35 PM
Last Post: wolfman5874
  Socket server problem H84Gabor 0 1,263 Jun-21-2022, 12:14 AM
Last Post: H84Gabor
Bug Problem connecting TLS client written in C++ and Twisted server gpropf 0 1,407 Jun-12-2022, 05:57 PM
Last Post: gpropf
  Server/client basic communication ebolisa 0 2,047 Sep-30-2021, 12:22 PM
Last Post: ebolisa
  Client server Multithreading Anan 6 5,945 Apr-21-2021, 08:19 PM
Last Post: SheeppOSU
Question Trouble with Client/Server reverse Shell! Gilush 0 2,808 Feb-03-2021, 01:04 PM
Last Post: Gilush
  Basic client server code question swisscheese 4 3,279 Dec-12-2020, 08:51 AM
Last Post: Larz60+
  How can i create a server for already existing client using Python? Chapanson 21 7,581 Aug-19-2020, 09:12 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020