Take the 2-minute tour ×

Is there a way (in the .NET framework) to set the source port on a UDP packet without using the Socket.Bind call? This particular socket only sends data. I'm using the SendTo method that takes the remote address and port. I don't want to bind to anything. However, my client software uses the source port of the UDP packet for the return path.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Setting the source address and port is the whole purpose of the bind call. Why would you want to avoid calling it? What is it that you think that binding the socket does that you don't want to do?

No, there does not exist a second/alternate way to set the source address and port. Binding the socket is the one and only way to do that.

share|improve this answer
Some of the other posts on SO seemed to indicate that there was a performance gain if I was to use separate sockets for sending and receiving data. In no circumstance can I have a send block a receive or vice-versa. –  Brannon May 31 '13 at 19:56
What is the bind call doing with the address parameter? It seems that it should just take a port. –  Brannon May 31 '13 at 19:57
This "performance gain" claim surprises me... or else it only applies in some specific context and I don't have in mind what that context is. Anyway, there's absolutely no reason why a receive should ever block on a send or vice versa. –  Celada May 31 '13 at 20:02
bind takes an address and a port and sets the local end of the socket to that address and port (or to any address if the address is INADDR_ANY) –  Celada May 31 '13 at 20:04
add comment

Your Answer


