Re: System.Net.Sockets.SocketException -UDP



Hallo Thomas,

> gib beim UdpClient-Konstruktor die (Empfangs-) Port-Nummer an, etwas wie:
>
> // hier zB 11000 als lokalen Port binden
> UdpClient udpClient = new UdpClient( 11000,
> AddressFamily.InterNetwork );
> IPEndPoint remoteIPEndPoint = new IPEndPoint( IPAddress.Any, 0 );
> byte[] receivedBytes = udpClient.Receive( ref remoteIPEndPoint );


Das hat in meinem Falle auch nicht so recht geholfen, auch wenn der Fehler
woanders liegen mag.
Ich möchte folgendes erreichen:
Wir haben im Netz mehrere Gateways, die auf Port 19000 auf ein UDP lauschen
und nach Erhalt ein Protokoll mit z.B. Speicherdaten zurücksenden. Die IPs
der Gateways sowie deren Anzahl kann variieren.
Mein Ansatz war, den Request erst einmal pauschal an alle Teilnehmer im Netz
zu schicken:

Byte[] sendBytes = Encoding.ASCII.GetBytes("SEARCH_REQUEST\r\n\r\n");
UdpClient udpClient = new UdpClient();
IPEndPoint remoteIpEndPoint = new IPEndPoint(IPAddress.Broadcast , 0);
udpClient.Send(sendBytes, sendBytes.Length, remoteIpEndPoint);


Das scheint auch zu klappen, nur beim Lauschen geht es scheinbar nicht
recht.

Byte[] receiveBytes = udpClient.Receive(ref receiveIpEndPoint);
string returnData = Encoding.ASCII.GetString(receiveBytes);
udpClient.Close();

Mit einem Networksniffer kann ich nachverfolgen, dass ein ein Gerät - immer
das selbe - antwortet, aber:
die Antwort erreicht mein .NET nicht und ein anderes Gerät scheint nicht zu
reagieren.

Es liegt nicht an den Geräten, da eine C++-Anwendung, die eigentlich genau
das machen sollte, was ich nachbaue, alle Geräte erreicht und auch eine
Antwort bekommt.

Viele Grüße,
Torben





"Thomas Scheidegger [MVP]" <spam.netmaster@xxxxxxxxxxxxxx> schrieb im
Newsbeitrag news:umiI0JOyFHA.3856@xxxxxxxxxxxxxxxxxxxxxxx
> Hallo Torben
>
>
> > ich sende ein UDP-Protocol und warte auf eine Antwort (die laut
> > UdpClient udp_listener = new UdpClient();
> > IPEndPoint receiveEndPoint = new IPEndPoint(IPAddress.Any ,0);
> > Byte[] receiveBytes;
> > receiveBytes = udp_listener.Receive( ref receiveEndPoint );
> //Hier kommt > ein Fehler!
>
>
> gib beim UdpClient-Konstruktor die (Empfangs-) Port-Nummer an, etwas wie:
>
> // hier zB 11000 als lokalen Port binden
> UdpClient udpClient = new UdpClient( 11000,
> AddressFamily.InterNetwork );
> IPEndPoint remoteIPEndPoint = new IPEndPoint( IPAddress.Any, 0 );
> byte[] receivedBytes = udpClient.Receive( ref remoteIPEndPoint );
>
>
>
> --
> Thomas Scheidegger - MVP .NET - 'NETMaster'
> http://www.cetus-links.org/oo_dotnet.html - http://dnetmaster.net/
>
>



.



Relevant Pages

  • Re: UDP deaf in WinService
    ... it binds to the port but totally fails to ... private void Implementation ... UdpClient listener = new UdpClient; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Bounding the same UDPClient to two threads
    ... manipulation of the UDPClient, cos I tought: ... about ICMP Port Unreachable messages... ... cos if I ... receiver has to know the port to answer to. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Bounding the same UDPClient to two threads
    ... There is absolutely nothing wrong with using a UDPClient created in one thread from a different thread, and in fact that's exactly how the async methods on UDPClient work, BeginSendTo). ... socket this error indicates a previous send operation resulted in an ICMP Port Unreachable message". ... There is no need to include the local port in the datagram, since the receiver can obtain that information directly from the ReceiveFrommethod. ... There is no well-defined specification for how NAT routers and proxies work (a plain firewall should leave the ports and in fact IP addresses alone, but of course most people aren't using a plain firewall alone), but any modern, well-behaved one uses a mapping table to maintain state of clients, and when it sees a particular IP/port sending a UDP datagram to a given endpoint, then communications received back from that endpoint will be automatically forwarded back to that particular IP/port, whether the port matches the destination endpoint or not. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: System.Net.Sockets.SocketException -UDP
    ... > // hier zB 11000 als lokalen Port binden ... > UdpClient udpClient = new UdpClient(11000, ... Wir haben im Netz mehrere Gateways, die auf Port 19000 auf ein UDP lauschen ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: UDPClient listen to any address, any port
    ... the specified NIC--and as soon as my app binds to a port, ... UDPClient or even one socket. ... > Dim udpClient as New Sockets.UDPClient) ...
    (microsoft.public.dotnet.languages.vb)

Loading