You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Important:** Obviously UdpClient requires a working network connection with a valid IP address. Please check the examples with the Network Helpers on how to connect to a network.
23
+
24
+
The UdpClient class provides simple methods for sending and receiving UDP datagrams on an IP network. The current implementation supports only IPv4. IPv6 isn't supported on nanoFramework currently.
25
+
26
+
### Samples
27
+
Samples for `UdpClient` are present in the [nanoFramework Sample repository](https://github.com/nanoframework/Samples).
28
+
29
+
### Remote host
30
+
Because UDP is a connectionless protocol you don't need to establish a remote host connection before sending and receiving data. But you can define a default remote host that will be used for subsequent `Send` method calls. If you establish a default remote host, you cannot specify a different host when sending datagrams. You can define a default remote host with one of the following methods:
31
+
- Create your client using the `UdpClient(string hostname,string remoteport)` constructor.
32
+
- Create an instance and then call the `Connect` method.
33
+
34
+
### Client usage
35
+
Using `UdpClient` in client mode is pretty easy. You create an UdpClient with one of the constructor, establish or not a default remote host (see above) then you can send and receive message from the network.
36
+
37
+
The following code show a typical client server exchange where you first send a message to the server and wait for the server answer:
Working as server you bind your `UdpClient` on a local port then you wait for messages from clients. As a server you don't know beforehand the IP address of your clients so you shouldn't define any remote host.
If you want to use multicast ensure that you bind your `UdpClient` on the `0.0.0.0` (wilcard) address. If you bind your UdpClient to a specific `IPAddress` you won't receive the multicast datagrams.
73
+
74
+
Basically for a functional multicast client/server you need to:
75
+
- Create your UdpClient without binding it to a specific address.
76
+
- Join a Multicast group by a call to the JoinMulticastGroup method.
77
+
- Receive datagram sent to that group address with call to `Receive`
78
+
- Send message to the group multicast using `Send`
79
+
- Leave the Multicast group by calling the `DropMulticastGroup` method
80
+
81
+
The following sample illustrate that basic workflow:
82
+
83
+
```C#
84
+
// Create your UdpClient without binding it to a specific address
If you want to receive your own messages you can enable this by setting the `UdpClient.MulticastLoopback` property to `true`.
111
+
20
112
## Feedback and documentation
21
113
22
114
For documentation, providing feedback, issues and finding out how to contribute please refer to the [Home repo](https://github.com/nanoframework/Home).
0 commit comments