概要
cscの作法、調べてみた。
udpを叩いてみた。
練習問題やってみた。
練習問題
ブロードキャストで、helloを送信して、返事を受け取る。
サンプルコード
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace ConsoleTest
{
class Program {
static void Main(string[] args) {
UdpClient udp = new UdpClient(50000);
udp.EnableBroadcast = true;
while (true)
{
Byte[] sendBytes = Encoding.ASCII.GetBytes("hello");
udp.Send(sendBytes, sendBytes.Length, new IPEndPoint(IPAddress.Broadcast, 49152));
Console.WriteLine(Encoding.ASCII.GetString(sendBytes));
IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, 0);
Byte[] receiveBytes = udp.Receive(ref endPoint);
string returnData = Encoding.ASCII.GetString(receiveBytes);
Console.WriteLine("recv: " + returnData.ToString());
}
}
}
}
以上。