sanyi
sanyi

Reputation: 6239

Python UDP client Ephemeral Reception Port

I have a multi threaded python application communicating with a separate service trough UDP.

Each thread is similar, at some point need a response from the separate service.

So practically for each thread I create e new client socket and start to communicate. The problem is on the server side each UDP packet seems to come from the same reception port thus this create problem on the client side on who receives whose message.

How can I enforce the socket to use a different ephemeral reception port for each instance in the same program different threads?

Thanks!

Upvotes: 1

Views: 713

Answers (1)

Nikolai Fetissov
Nikolai Fetissov

Reputation: 84151

You can connect() each UDP socket to it's target. That way the ephemeral ports will be fixed (and different) for each thread.

Upvotes: 2

Related Questions