Difference between revisions of "Programmering III December"
From Teknologisk videncenter
(Created page with "===UDP listener:=== '''Server:''' <source lang="Csharp"> UdpClient client = new UdpClient(11000); IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, 11000); ...") |
(→UDP listener:) |
||
Line 11: | Line 11: | ||
Console.WriteLine(result); | Console.WriteLine(result); | ||
+ | Console.ReadKey(); | ||
+ | </source> | ||
+ | |||
+ | |||
+ | ===UDP sender:=== | ||
+ | |||
+ | '''Server:''' | ||
+ | <source lang="Csharp"> | ||
+ | UdpClient client = new UdpClient(); | ||
+ | IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 11000); | ||
+ | byte[] myBytes = Encoding.ASCII.GetBytes("Hello!"); | ||
+ | client.Send(myBytes, myBytes.Length, endPoint); | ||
+ | |||
+ | Console.WriteLine("Message has been sent!"); | ||
Console.ReadKey(); | Console.ReadKey(); | ||
</source> | </source> |
Revision as of 08:48, 13 December 2016
UDP listener:
Server:
UdpClient client = new UdpClient(11000);
IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, 11000);
byte[] recivedBytes = client.Receive(ref endpoint);
Console.WriteLine("The message was:");
string result = Encoding.ASCII.GetString(recivedBytes);
Console.WriteLine(result);
Console.ReadKey();
UDP sender:
Server:
UdpClient client = new UdpClient();
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 11000);
byte[] myBytes = Encoding.ASCII.GetBytes("Hello!");
client.Send(myBytes, myBytes.Length, endPoint);
Console.WriteLine("Message has been sent!");
Console.ReadKey();