|
4 | 4 | // dotnet run --p StartupObject=UdpNamespace.Udp
|
5 | 5 |
|
6 | 6 | using System;
|
7 |
| -using System.Net; |
8 |
| -using System.Net.Sockets; |
9 |
| -using System.Text; |
| 7 | +using System.Net; // VER: network_udp_send,network_udp_recv |
| 8 | +using System.Net.Sockets; // VER: network_udp_send,network_udp_recv |
| 9 | +using System.Text; // VER: network_udp_send,network_udp_recv |
10 | 10 |
|
11 | 11 | namespace UdpNamespace {
|
12 | 12 | public class Udp {
|
13 | 13 | Udp() {
|
14 |
| - Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); |
| 14 | + Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); // VER: network_udp_send,network_udp_recv |
15 | 15 |
|
16 | 16 | // ping host.docker.internal -> 192.168.5.2
|
17 | 17 | //IPEndPoint addr = new IPEndPoint(IPAddress.Parse("192.168.5.2"), 64488);
|
| 18 | + |
| 19 | + IPEndPoint addr = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5005); // VER: network_udp_send |
| 20 | + byte[] data = Encoding.ASCII.GetBytes("Hello World!"); // VER: network_udp_send |
| 21 | + sock.SendTo(data, addr); // VER: network_udp_send |
| 22 | + Console.WriteLine($"Bound to {sock.LocalEndPoint}"); // VER: network_udp_send |
| 23 | + |
18 | 24 | /*
|
19 |
| - IPEndPoint addr = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5005); |
20 |
| - byte[] data = Encoding.ASCII.GetBytes("Hello World!"); |
21 |
| - sock.SendTo(data, addr); |
22 |
| - Console.WriteLine($"Bound to {sock.LocalEndPoint}"); |
| 25 | + verified with |
| 26 | + docker exec -it e0cdcbd43842 /bin/sh |
| 27 | + nc -u 127.0.0.1 5005 |
| 28 | + So it's something wrong with udp to the container |
23 | 29 | */
|
24 | 30 |
|
25 |
| - sock.Bind(new IPEndPoint(IPAddress.Any, 5005)); |
26 |
| - byte[] buf = new byte[1024]; |
27 |
| - while (true) { |
28 |
| - int bytesReceived = sock.Receive(buf); |
29 |
| - String msg = System.Text.Encoding.UTF8.GetString(buf, 0, bytesReceived); |
30 |
| - Console.WriteLine($"received bytes: {msg} from ???"); |
31 |
| - } |
| 31 | + //sock.Bind(new IPEndPoint(IPAddress.Any, 5005)); // VER: network_udp_recv |
| 32 | + byte[] buf = new byte[1024]; // VER: network_udp_recv |
| 33 | + while (true) { // VER: network_udp_recv |
| 34 | + //Console.WriteLine($"Read {sock.LocalEndPoint}"); |
| 35 | + int bytesReceived = sock.Receive(buf); // VER: network_udp_recv |
| 36 | + String msg = System.Text.Encoding.UTF8.GetString(buf, 0, bytesReceived); // VER: network_udp_recv |
| 37 | + Console.WriteLine($"received bytes: {msg} from ???"); // VER: network_udp_recv |
| 38 | + } // VER: network_udp_recv |
32 | 39 | }
|
33 | 40 | public static void Main(string[] args) {new Udp();}
|
34 | 41 | }
|
|
0 commit comments