UDP Two Sockets, One port, Local

Is it possible for a packet to be sent to a specific socket that is listening on the same port as another socket in a different application, in UDP.

At the moment, it only picks one of the sockets to always send the packets to (the first socket listening). the second socket doesn’t receive anything.

Visualization:

I have a SERVER, and two sockets, SOCKET1 and SOCKET2.

SOCKET1 listening on 127.0.0.1:1837
SOCKET2 listening on 127.0.0.1:1837

SERVER sending packet to 127.0.0.1:1837

SOCKET1 will always receive the packets, can i specify for SOCKET2 to receive certain packets, and SOCKET1 certain others?

Nope.

Just sort them yourself? If YOU can’t do that, how do you expect the OS to do it for you? xd

like I said, only first socket receives the packets.

darn ittt there must be a work around?

I’ve been trying to work out why you need to do this…?
Why not just use another port for socket2 or filter the packets from socket1?

You should have gotten an exception when you attempted to bind two sockets to the same port. The only way you can bind two sockets to the same port is with multicast, and I suspect that’s not actually what you’re after.

it is multicast (as intended), problem is both sockets don’t receive the packets, only one does.

EDIT: fixeddddd

127.0.0.1 is not a multicast address, and you are not using a multicast API. Just saying it’s multicast does not make it multicast. I’d link to the proper API for multicast sockets, but I really don’t want to confuse the issue further than I already have.

I’m aware… doesn’t change the fact that the sockets are listening on 127.0.0.1

counterp, how did you fix it?

I was trying to send a UDP packet to a SocketAddress instead of a group (I was using multicast sockets), but when I do this, it only sends it to the first socket registered (instead of all sockets listening on that specific address and port). I could send a UDP packet to the whole group, and everyone, including the two sockets listening on the same address and port would receive it.

I didn’t want that though because the information sent had to do with sending a unique ID to a specific client that I wanted to remain private.

I just used TCP in the end since it’s a one time thing (sends ID on login), and I also needed reliability for this. (should have done this from beginning)