UdpClient class question? (How to release the bound port) [modified]
-
Hi all, I have a problem with the udpClient class. Here are the details. I am creating an instance of udpClient class with the following constructer;
UdpClient myUdp = new UdpClient();
// I don't want to use the constructer "UdpClient myUdp = new UdpClient(localPortNo);
" So 1) what is the method that I should call to assign my listening port (local port number) for incoming udp packets? 2) How can unbind the port without deallocating all the sources related to the socket? i.e If I close my socket with the "close()
" method than all the resources related to the socket are made free. Instead I just want to release the local port. Best Regards zafersavas -- modified at 18:08 Saturday 24th February, 2007 -
Hi all, I have a problem with the udpClient class. Here are the details. I am creating an instance of udpClient class with the following constructer;
UdpClient myUdp = new UdpClient();
// I don't want to use the constructer "UdpClient myUdp = new UdpClient(localPortNo);
" So 1) what is the method that I should call to assign my listening port (local port number) for incoming udp packets? 2) How can unbind the port without deallocating all the sources related to the socket? i.e If I close my socket with the "close()
" method than all the resources related to the socket are made free. Instead I just want to release the local port. Best Regards zafersavas -- modified at 18:08 Saturday 24th February, 2007You haven't said why you don't want to use the overloaded constructor to instanciate the client and specify the port. The problem is that in order to listen for incoming data, you use the UdpClient.Receive method. This method blocks until data is received, and with UDP being a connectionless protocol, you can never guarantee when data will be recieved so your left with having to listen for any/all incoming data over a specific port. One way to achieve this is to run a UdpClient that listens for incoming data on a seperate thread which frees up the main thread to do it's normal work. A seperate UdpClient can then be instanciated in the main thread whenever you need to send data. I created a test project some time ago which you can download from here: http://www.box.net/public/frq1a08ozh It requires v2.0 of the .Net Framework but the source code should help point you in the right direction even if you using v1.1 Hope this helps
Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students View my Blog