473,394 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

UdpClient throws Socket Exception on subsequent Send calls

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
2 5176
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Piotr Bieniek | last post by:
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...
0
by: Stephan Steiner | last post by:
Hi The project I'm currently working on involves sending large UDP broadcasts. As the .NET framework already provides an easy facility for sending and receiving UDP packets I thought it was a...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
1
by: Dan Kelley | last post by:
I have 2 projects - 1 Winform project that sends Udp messages using the UdpClient class when a button is clicked, and a Console application that listens for these Udp messages. If I try to use...
2
by: Rick | last post by:
Hi, I'm trying to get a simple UdpClient app working. I've been looking at the MSDN info regarding UdpClient. When I set it up on my own PC and send messages to myself it works OK. If I try to...
1
by: Steve | last post by:
Please take a look at the simple code segment below and advise me what is wrong. According to the help and examples I've seen it should work unless I misunderstand something. The problem is...
2
by: Emilio | last post by:
Question about UdpClient sample ' This constructor arbitrarily assigns the local port number. Dim udpClient As New UdpClient() Try udpClient.Connect("www.contoso.com", 11000) ' Sends a...
1
by: Plem | last post by:
Hi All, I've allready posted this on the C# group (oops). I'm trying to get a UDPclient to receive. I use the sample code provided in HELP but to nbo avail. When the receive method is...
7
by: | last post by:
I have the following program using System; using System.Collections; using System.Net.Sockets; using System.Net; using System.IO; public class Test { public static void Main(string s) {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.