By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,696 Members | 2,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,696 IT Pros & Developers. It's quick & easy.

UdpClient throws SocketException of subsequent Send calls

P: n/a
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
--
Piotr Bieniek
pb******@op.nospam.pl

Do not type "nospam" in my address, if you want to contact me.


Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.