473,320 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

UDP - Changing Socket Properties

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
1 3045
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jody Burgess | last post by:
Hi; I am writing my first python program and would like to know how to change stdout to refer to my default printer or any other printer on my network. The other question is, Is there an API set...
3
by: Aaron | last post by:
tcpclient socket webrequest what are each used for? I read some reference books and did some research on the internet, but I'm still confused. could someone clarify this for me? Thanks,...
4
by: DreJoh | last post by:
I've read many articles on the subject and the majority of them give the same solution that's in article 821625 on the MSDN website. I'm using the following code and when a the client disconnects...
3
by: Robert A. van Ginkel | last post by:
Hello Fellow Developer, I use the System.Net.Sockets to send/receive data (no tcpclient/tcplistener), I made a receivethread in my wrapper, the receivethread loops/sleeps while waiting for data...
1
by: Joe | last post by:
Hi, I browsed the news and a few seem to have this problem too, but no solution ! I have a client server application where in case the connection gets bad (crashes or whatever) client or...
2
by: Droopy | last post by:
Hi, I try to implement a reusable socket class to send and receive data. It seems to work but I have 2 problems : 1) I rely on Socket.Available to detect that the connection is closed (no...
10
by: 7stud | last post by:
Hi, I'm experimenting with a basic socket program(from a book), and both the client and server programs are on my computer. In both programs, I call socket.gethostname(), but I discovered that...
0
by: Dan Avni | last post by:
i have a tcp server that listens to a port using the TcpListener class. clients are connecting to the server and once the connection is opened the connection is left open and the client sends data...
1
by: ElvisRS | last post by:
Hi, I'm writing a simple udp client using sockets. My code looks like this: initServer2 = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.