Avatar of alexatsearidge
alexatsearidge
Flag 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.
.NET ProgrammingC#

Avatar of undefined
Last Comment
multithreading

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
multithreading

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
multithreading

Does "no points refunded" mean the question is marked as having been answered, with points assigned?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy