troubleshooting Question

UdpClient doesn't release port

Avatar of alexatsearidge
alexatsearidgeFlag for Canada asked on
.NET ProgrammingC#
2 Comments1 Solution482 ViewsLast Modified:
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
multithreading

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros