P
Piotr Bieniek
Hello,
I have a problem with UDP sockets. It concerns UdpClient class as well. It
throws strange exceptions on subsequent Send calls. Exception is
SocketException with native error code 10049. I noticed that it happens when
I call Send for the second time in my program. It seemed strange, so I
compiled and run Chat sample program from MSDN. To my surprise, it worked.
But then I modified it. The only change was that I duplicated sending code,
so the program should send two packets instead of one and the exception was
thrown.
What am I doing wrong?
Here is the source code that ilustrates my problem:
---
UdpClient m_Client=new UdpClient();
IPEndPoint m_RemoteEP=new IPEndPoint(0x2301000A, 12434);
for (;
{
string s="abc";
byte [] buffer = new Byte[s.Length + 1];
int len = System.Text.Encoding.ASCII.GetBytes( s.ToCharArray(), 0,
s.Length, buffer, 0);
int ecode = m_Client.Send(buffer, len, m_RemoteEP);
System.Threading.Thread.Sleep(1000);
}
---
Exception is thrown when m_Client.Send is thrown for the second time. IP
Address in m_RemoteEP declaration does not matter. If I first call Connect
(outside the loop) and then use Send without m_RemoteEP, it does not help.
Thanks in advance
I have a problem with UDP sockets. It concerns UdpClient class as well. It
throws strange exceptions on subsequent Send calls. Exception is
SocketException with native error code 10049. I noticed that it happens when
I call Send for the second time in my program. It seemed strange, so I
compiled and run Chat sample program from MSDN. To my surprise, it worked.
But then I modified it. The only change was that I duplicated sending code,
so the program should send two packets instead of one and the exception was
thrown.
What am I doing wrong?
Here is the source code that ilustrates my problem:
---
UdpClient m_Client=new UdpClient();
IPEndPoint m_RemoteEP=new IPEndPoint(0x2301000A, 12434);
for (;
{
string s="abc";
byte [] buffer = new Byte[s.Length + 1];
int len = System.Text.Encoding.ASCII.GetBytes( s.ToCharArray(), 0,
s.Length, buffer, 0);
int ecode = m_Client.Send(buffer, len, m_RemoteEP);
System.Threading.Thread.Sleep(1000);
}
---
Exception is thrown when m_Client.Send is thrown for the second time. IP
Address in m_RemoteEP declaration does not matter. If I first call Connect
(outside the loop) and then use Send without m_RemoteEP, it does not help.
Thanks in advance