Back to Browse

simpleudpsever in C#

1.3K views
May 1, 2017
6:10

first of all add two important Library for udpclient to work 1).Using System.Net; 2).Using System.Net.Sockets; inside of the main program 1).initailize udpclient(sever) with a listerning port number eg 8080 UdpClient client = new UdpClient(8080); 2).ontain any ip address of a client and port number on client IPEndPoint remoteip = new IPEndpoint(IPAddress.any,8080); 3).receive byte of data from client ipaddress bytes[] receivedbytes=client.Receive(ref remoteip); 4).adding condtion to indicate if we receive data if(receivedbytes!=null){} 5).if receivedbytes not equal to null then we convert receivedbytes to string and display onto aconsole string message= Encoding.ASCII.GetString(receiveddbytes); 6).display the message onto a console screen Console.writeLine("received message :" +message); 7).avoiding a console screen from exiting Console.ReadLine();

Download

0 formats

No download links available.

simpleudpsever in C# | NatokHD