Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- using System.Net.Sockets;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConnectPort
- {
- class Program
- {
- static void Main(string[] args)
- {
- int port = 9999;
- IPEndPoint ipEnd = new IPEndPoint(IPAddress.Any, port);
- Console.WriteLine(">>> Server Start On Port "+ port);
- Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
- sock.Bind(ipEnd);
- sock.Listen(100);
- Socket clientSock = sock.Accept();
- byte[] clientData = new byte[1024];
- int receivedBytesLen;
- Console.WriteLine(">>> Accept Client");
- Console.WriteLine();
- receivedBytesLen = clientSock.Receive(clientData);
- string clientDataInString = Encoding.ASCII.GetString(clientData, 0, receivedBytesLen);
- Console.WriteLine("Received Data {0}", clientDataInString);
- while(clientSock.Connected)
- {
- try
- {
- string clientStr = "Client Data Received";
- byte[] sendData = new byte[1024];
- sendData = Encoding.ASCII.GetBytes(clientStr);
- clientSock.Send(sendData);
- }
- catch
- {
- }
- sock.Close();
- }
- clientSock.Close();
- Console.WriteLine(">>> Exit!");
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement