Listening for sockets : TcpListener : Network C# Examples


C# Examples » Network » TcpListener »

 

Listening for sockets









    
using  System;
using  System.Net;
using  System.Text;
using  System.Net.Sockets;

class  MainClass
{
    [STAThread]
    static  void  Main(string[]  args)
    {
        int  PortNumber  =  10000;
        TcpListener  MyListener  =  new  TcpListener(IPAddress.Parse("127.0.0.1"),  PortNumber);

        MyListener.Start();

        Console.WriteLine("Waiting  For  Connection");
        TcpClient  MyClient  =  MyListener.AcceptTcpClient();

        Console.WriteLine("Connection  Accepted");

        NetworkStream  MyNetStream  =  MyClient.GetStream();
        String  Response  =  "accepted";
        Byte[]  SendTheseBytes  =  Encoding.ASCII.GetBytes(Response);

        MyNetStream.Write(SendTheseBytes,  0,  SendTheseBytes.Length);
        MyClient.Close();
        MyListener.Stop();
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Network
» TcpListener