timeout beim Empfangen & Versende von Nachrichten übers Netzwerk

K

Karolin Spill

Hallo NG,

ich schreibe ein Programm in c# und benutze einen UdpClient, um Datenpackete
übers Netzwerk an einen Server zu schicken. Dabei erfolgt immer erst eine
Anfrage vom Client an den Server und der Server schickt dann eine Antwort.
Ich habe jedoch bis jetzt nicht herausgefunden, wie ich ein Timeout setzen
kann.
Weiß jmd, wie man das macht?
Ab und zu scheint nämlich ein Paket verloren zu gehen und wenn ich dann
keine Antwort bekomme, dann
hänge ich in der Receive-Funktion fest. Dann geht garnichts mehr.
Hier ist ein CodeSchnipsel:

....Code...

Client = new UdpClient(IP, Port);

....Code...

int nByteSent;

byte[]inputToBeSent= new byte[50];

nBytesSent = Client.Send(inputToBeSent,inputToBeSent.Length);

....Code..

IPHostEntry remoteHostEntry = Dns.GetHostByName(IP);

IPEndPoint remoteIpEndPoint = new IPEndPoint(remoteHostEntry.AddressList[0],
Port);

received = Client.Receive(ref remoteIpEndPoint);



Bin dankbar für jeden Hinweis
 
K

Karolin Spill

ups sorry, I just forgot to write in English
ok, here is my question in english:

I am writing a program in c# and am using a UdpClient to send packages with
data over the network
to a server. Each time, I first send a request to the server and then I
receive an answer.

But until now I could not discover how to set the timeout.
Does anybody know how to do that?
Every now and then a package gets lost and this is when I do not receive an
answer and the program hangs up.
Here is a code snippet:

....Code...
Client = new UdpClient(IP, Port);

...Code...

int nByteSent;

byte[]inputToBeSent= new byte[50];

nBytesSent = Client.Send(inputToBeSent,inputToBeSent.Length);

...Code..

IPHostEntry remoteHostEntry = Dns.GetHostByName(IP);

IPEndPoint remoteIpEndPoint = new IPEndPoint(remoteHostEntry.AddressList[0],
Port);

received = Client.Receive(ref remoteIpEndPoint);
Thank you for every hint


Karolin Spill said:
Hallo NG,

ich schreibe ein Programm in c# und benutze einen UdpClient, um Datenpackete
übers Netzwerk an einen Server zu schicken. Dabei erfolgt immer erst eine
Anfrage vom Client an den Server und der Server schickt dann eine Antwort.
Ich habe jedoch bis jetzt nicht herausgefunden, wie ich ein Timeout setzen
kann.
Weiß jmd, wie man das macht?
Ab und zu scheint nämlich ein Paket verloren zu gehen und wenn ich dann
keine Antwort bekomme, dann
hänge ich in der Receive-Funktion fest. Dann geht garnichts mehr.
Hier ist ein CodeSchnipsel:

...Code...

Client = new UdpClient(IP, Port);

...Code...

int nByteSent;

byte[]inputToBeSent= new byte[50];

nBytesSent = Client.Send(inputToBeSent,inputToBeSent.Length);

...Code..

IPHostEntry remoteHostEntry = Dns.GetHostByName(IP);

IPEndPoint remoteIpEndPoint = new IPEndPoint(remoteHostEntry.AddressList[0],
Port);

received = Client.Receive(ref remoteIpEndPoint);



Bin dankbar für jeden Hinweis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top