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

UdpClient throws Socket Exception on 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.


Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hello,
The 10049 SocketException is "Address not available from the local
machine". Your code sample shows you are trying to send the UDP packet
to IP address 10.1.0.35, which is an unroutable network address
(similar to the 192.168. network). Is your test PC also on the 10.
network? If not, there is no way for this packet to get to the
destination. Hope this helps solve your problem.


Thanks a lot, but it's not the case. My computer is in the same subnet and
if I change destination IP address to another (for example 213.180.130.200,
which is routable) it doesn't help either. What's very strange is that the
first packet is sent (my firewall warns me about it), but the exception is
thrown when I call Send method for the second time.

Can you compile my source and reproduce the problem? Maybe it's something
with my .NET Framework version...

Anyway, thanks a lot for your time.

Piotr Bieniek
pb******@op.nospam.pl

Do not type "nospam" in my address, if you want to contact me.
Nov 13 '05 #2

P: n/a
Hello,

The problem solved. Of course it had nothing with programming. After turning
off my personal firewall my problems disappeared. :)
--
Piotr Bieniek
pb******@op.nospam.pl

Do not type "nospam" in my address, if you want to contact me.
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.