UDP - Changing Socket Properties

R

Rolln_Thndr

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.
 
R

Rolln_Thndr

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.






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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top