how to bind/connect multiple UDP socket

Posted by nicboul on Stack Overflow See other posts from Stack Overflow or by nicboul
Published on 2010-06-03T16:44:10Z Indexed on 2010/06/03 17:34 UTC
Read the original article Hit count: 246

Filed under:
|
|

My initial UDP socket is binded to 127.0.0.1:9898.

The first time that I get notified of incoming data by epoll/kqueue, I do recvfrom() and I fill a struct sockaddr called peer_name that contain the peer informations (ip:port).

Then I create a new UPD socket using socket(),

then I bind() this newly created socket to the same ip:port (127.0.0.1:9898) than my original socket.

then I connect my newly created socket using connect() to the peer who just sent me something. I have the information in the struct sockaddr called peer_name.

I then add my newly created socket in my epoll/kqueue vector and wait for notification.

I would expect to ONLY receive UDP frame from the peer i'm ""connected to"".

1/ does netstat -a -p udp is suppose to show me the IP:PORT of the peer my newly created socket is ""connected to"" ?

2/ I'm probably doing something wrong since after creating my new socket, this socket receive all incoming UDP packets destinated to the IP:PORT I'm binded to, regardless of the source peer IP:PORT.

I would like to see a working example of what I'm trying to do :) or any hint on what I'm doing wrong.

thanks!

© Stack Overflow or respective owner

Related posts about c

    Related posts about socket