Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Net;
- using System.Net.Sockets;
- using System.Threading;
- namespace ServerUDP
- {
- class Server
- {
- static void Main()
- {
- Servers();
- }
- static void Servers()
- {
- int receivedDataLength;
- byte[] data = new byte[1024];
- byte[] resp = new byte[1024];
- IPEndPoint ip = new IPEndPoint(IPAddress.Any, 9999);
- Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
- socket.Bind(ip);
- IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
- EndPoint Remote = (EndPoint)(sender);
- while (true)
- {
- data = new byte[1024];
- receivedDataLength = socket.ReceiveFrom(data, ref Remote);
- Console.WriteLine(Encoding.ASCII.GetString(data, 0, receivedDataLength));
- string hello = "Hello Client";
- resp = Encoding.ASCII.GetBytes(hello);
- socket.SendTo(resp, resp.Length, SocketFlags.None, Remote);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment