Questions tagged [udpclient]

UdpClient (System.Net.Sockets.UdpClient) is a .NET-Class allowing to send and receive UDP-Traffic.

575 questions
8
votes
4 answers

await UDPClient.ReceiveAsync with timeout

I'm using UDPClient like below dim c = New UDPClient(port) client.CLient.ReceiveTimeout = 1 await client.ReceiveAsync() However the await does not terminate or throw even though I have set a timeout. Is this normal behaviour?
bradgonesurfing
  • 30,949
  • 17
  • 114
  • 217
7
votes
2 answers

Get client IP from UDP packages received with UdpClient

I am developing an action multiplayer game with the help of the System.Net.Sockets.UdpClient class. It's for two players, so one should open a server and wait for incoming connections. The other player inputs the host IP and tries to send a "ping",…
magnattic
  • 12,638
  • 13
  • 62
  • 115
7
votes
6 answers

(Apparently) Gracefully Closed UDPClient leaves the socket blocked

The following code, despite apparently closing the UDP Socket, leaves it hanging and unable to reconnect to the same address / port. These are the class variables I use: Thread t_listener; List XSensAvailablePorts; private…
Saverio Terracciano
  • 3,885
  • 1
  • 30
  • 42
7
votes
1 answer

recvfrom() not filling the from IP address even for UDP messages in first call

I am using recvfrom() to get the UDP datagram into my buffer and passing non-NULL from_addr structure & len argument expecting it to get the source IP. But for the first call, they are NULL. Subsequent calls are filling the addr structure and len…
Anil Kumar K K
  • 1,395
  • 1
  • 16
  • 27
7
votes
2 answers

How do I find the port number assigned to a UDP client (in .net/C#)?

If I create a socket using var socket = new UdpClient(0,AddressFamily.InterNetwork); How do I then find the port of the socket? I'm probably being daft, but I'm not having luck in MSDN/Google (probably because it is 4:42 on a Friday and the sun…
Charley Rathkopf
  • 4,720
  • 7
  • 38
  • 57
6
votes
0 answers

UDP Client not receiving messages on linux machines

I have a program to discover clients on network, The class libraries which responsible for the discovery are .net standard 2. It works perfect on windows machines but now i need to run it on linux and my UdpClient not receiving the messages, Even…
ATT
  • 921
  • 3
  • 13
  • 30
6
votes
1 answer

How to get UDP data constant listening on Kotlin

I am looking for a way to trigger the function named receiveUDP each time a UDP packet is received. How can can I do that on Kotlin? Here is the code I currently have working like a simple chat. It uses 01 editText for user input, 01 textView for…
Wodie
  • 111
  • 1
  • 7
6
votes
1 answer

Killing a blocked UDP socket

Let's assume I have an UDP socket that was open on a certain address / port and then hanged. When I try to initialize a new UDP Socket (UDPClient) on that same address / port of course it raises a SocketException since it finds that is already in…
Saverio Terracciano
  • 3,885
  • 1
  • 30
  • 42
6
votes
2 answers

UdpClient, Receive() right after Send() does not work?

Consider the following code: client.Send(data, data.Length, endpoint); byte[] response = client.Receive(ref endpoint); While, according to WireShark (network sniffer), the remote host does reply with data, the application here just waits for data…
TimothyP
  • 21,178
  • 26
  • 94
  • 142
6
votes
3 answers

How do you 'cancel' a UdpClient::BeginReceive?

I have a thread which sits around waiting for UDP messages from multiple interfaces using UdpClient::BeginReceive and a callback which calls UdpClient::EndReceive to pick up the data and pass it on. If after 5 seconds I don't get anything, I return…
Jon Cage
  • 36,366
  • 38
  • 137
  • 215
6
votes
3 answers

UDP: Read data from all network interfaces

I've the following code to read multicast message coming from the network, for a specified IP+Port private static void ReceiveMessages(int port, string ip, CancellationToken token) { Task.Factory.StartNew(() => { using (var…
J4N
  • 19,480
  • 39
  • 187
  • 340
6
votes
2 answers

Receiving UDP Broadcast message in C#

I know this question has been asked many times. I've read ALL the answers and tried EVRY piece of code I could find. After a few days I'm so desperate that I have to ask you for help. I have a device and a PC in my home network. The device sends UDP…
Boris
  • 8,551
  • 25
  • 67
  • 120
5
votes
3 answers

How do I know if UdpClient has been closed/disposed?

I am receiving data from UdpClient via the usual async callback: private void OnUdpData(IAsyncResult result) { byte[] data = _udpReceive.EndReceive(result, ref _receiveEndPoint); //Snip doing stuff with data …
GazTheDestroyer
  • 20,722
  • 9
  • 70
  • 103
5
votes
2 answers

UDP - Can I send two datagram parts, and make the receiving end combine them into one?

This is maybe a stupid question, but since I am relatively new to UDP here it goes... If I am having two separate byte arrays that I need the receiving side to get as one big array, for example: byte[] Array1 = {1,1,1} byte[] Array2 = {2,2,2} Can I…
Cipi
  • 11,055
  • 9
  • 47
  • 60
5
votes
3 answers

Sending objects with UdpClient C#

I'm currently testing in visual studio 2010. I made a client and server which both will connect through UdpClient. I want to send an object from the client to the server. I have two methods to convert the object to bytes and to convert it to an…
kendepelchin
  • 2,680
  • 2
  • 21
  • 25
1
2
3
38 39