Difference between revisions of "Programmering IV December"

From Teknologisk videncenter
Jump to: navigation, search
(Created page with "Server: //Listens for data. static void Main(string[] args) { UdpClient client = new UdpClient(11000); IPEndPoint endpoint = n...")
(No difference)

Revision as of 08:31, 6 December 2016

Server:


       //Listens for data.
       static void Main(string[] args)
       {
           UdpClient client = new UdpClient(11000);
           IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, 11000);
           byte[] recivedBytes = client.Receive(ref endpoint);
           string result = Encoding.ASCII.GetString(recivedBytes);
           Console.WriteLine(result);


           Console.ReadLine();
       }




Client:

       //Sends 100 packages
       static void Main(string[] args)
       {
           UdpClient client = new UdpClient();
           IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 11000);
               byte[] messageBytes = Encoding.ASCII.GetBytes("Hello!");
               client.Send(messageBytes, messageBytes.Length, endpoint);
       }