Link to home
Start Free TrialLog in
Avatar of alexatsearidge
alexatsearidgeFlag for Canada

asked on

UdpClient doesn't release port

Hi all, coding C# in VS.NET 2005

I'm using the following code.
-----
// Receive a message and write it to the console.
UdpClient u = new UdpClient(m_ipEndPoint);

UdpState s = new UdpState();
s.e = m_ipEndPoint;
s.u = u;

u.BeginReceive(new AsyncCallback(ReceiveCallback), s);

while (!messageReceived)
     Thread.Sleep(100);

s.u.Close();    
-----
The code executes fine the first time, the callback is handled properly.  My problem is that s.u.Close() does not release the port, so the next time this code executes "UdpClient u = new UdpClient(m_ipEndPoint);" it throws an exception saying the port is already in use.
ASKER CERTIFIED SOLUTION
Avatar of multithreading
multithreading

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of multithreading
multithreading

Does "no points refunded" mean the question is marked as having been answered, with points assigned?