B
B
BadCats2021-08-03 20:23:06
Python
BadCats, 2021-08-03 20:23:06

Determine what came to the server - a packet or a segment (udp / tcp)?

Let's start with the fact that there is a segment - as a unit of data at the transport level, and there is a segment in the context of the TCP protocol - the amount of data transmitted at a time. In this question, it is the latter that is implied.
There is a client-server chat on sockets - written in python. At the time of connection of the client - he (the client) can choose how to send the message to the server. How to determine from the server side - the type of the incoming message - its transport protocol and, depending on this, respond to different clients? Those. you need a kind of packet sniffer (packets in the general sense - a la messages). Where can you read about something like this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Valentin, 2021-08-03
@BadCats

It is not clear why the sniffer. Programmatically, both under tcp and under udp, different sockets are opened and transferred to the LISTEN state. Which one to choose for a new connection is decided by the operating system based on incoming packets (the network stack itself analyzes the packets). And if you still need to give more flexibility, there is iptables.

K
ky0, 2021-08-03
@ky0

You don't need to sniff anything to understand if a TCP packet or UDP packet arrived - they will arrive on different ports, respectively - you can implement different processing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question