By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,376 Members | 1,599 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,376 IT Pros & Developers. It's quick & easy.

UDP - Changing Socket Properties

P: n/a
I'm vey new to network programing and have a few rather fundemental questions.

I'm creating a very basic UDP proxy server and having a few issues regarding the sockets. Is it possible to change the properties of a socket WITHOUT closing it and creating a new one?

Basically, I need to change the port of a bound socket, but the only way I have found to do this so far is to close the exisitng socket and create a new one. This in itself isn't hard to do but my app is threaded and I run into complications when a one thread is blocking on the socket's ReceiveFrom method. I have to kill the thread, close the socket, change the local endpoint port property, recreate the socket, bind it and then start a new thread which then awaits the incoming datagrams again.

Maybe I'm missing something and this may be the only way to do it, but it seems really complex. Not too mention I'm not sure what the implications will be when I stop and start one of the 'listening' threads, I don't want to miss any datagrams that are sent to the proxy while I'm changing the local endpoint the socket is bound to.

Any advice would be great. I've done a lot of looking around and haven't found any info that deals with 'changing' socket properties once a socket has been created. I've also purchased "C# Network Programming" by Richard Blum, which is a great book but I haven't found anything about this in their either.

Thanks.
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Also, here is a basic flow of the way I wrote it...

MainClass
-Creates a static ProxyToClient Socket
-Creates a static ProxyToServer Socket
-Binds them
-Creates a starts to threads

Thread1
-Listens on the ProxyToClient socket for data from the client (socket is blocking until data is received)
-Forwards data to the server on the ProxyToServer socket

Thread2
-Listens on the ProxyToServer socket for the data from the server (socket is blocking until the data is received)
-Forwards data to the client on the ProxyToClient socket

At some point, the data from the server contains a port number that the client is supposed to send to. Once this port number has been received by the proxy, it needs to change the port number that the ProxyToClient socket is 'listening' on. It monitors for the port number in Thread2, the only way I've found to change the ProxyToClient port number is to kill Thread1, close the ProxyToClient socket and recreate everything with the correct parameters.

I'm using Bind and SendTo/ReceiveFrom, not using the UdpClient helper class.




"Rolln_Thndr" <ro*********@hotmail.com> wrote in message news:eN**************@TK2MSFTNGP10.phx.gbl...
I'm vey new to network programing and have a few rather fundemental questions.

I'm creating a very basic UDP proxy server and having a few issues regarding the sockets. Is it possible to change the properties of a socket WITHOUT closing it and creating a new one?

Basically, I need to change the port of a bound socket, but the only way I have found to do this so far is to close the exisitng socket and create a new one. This in itself isn't hard to do but my app is threaded and I run into complications when a one thread is blocking on the socket's ReceiveFrom method. I have to kill the thread, close the socket, change the local endpoint port property, recreate the socket, bind it and then start a new thread which then awaits the incoming datagrams again.

Maybe I'm missing something and this may be the only way to do it, but it seems really complex. Not too mention I'm not sure what the implications will be when I stop and start one of the 'listening' threads, I don't want to miss any datagrams that are sent to the proxy while I'm changing the local endpoint the socket is bound to.

Any advice would be great. I've done a lot of looking around and haven't found any info that deals with 'changing' socket properties once a socket has been created. I've also purchased "C# Network Programming" by Richard Blum, which is a great book but I haven't found anything about this in their either.

Thanks.
Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.