예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SocketServerAsync"/> class with specified local point.
 /// </summary>
 /// <param name="localEndPoint">The <see cref="IPEndPoint"/> class.</param>
 public SocketServerAsync(IPEndPoint localEndPoint)
 {
     LocalEndPoint  = localEndPoint;
     _listener      = new TcpListener(localEndPoint);
     _socketClients = new ConcurrentBag <SocketClientBase>();
     ServerStatus   = SocketServerStatus.Stop;
 }
예제 #2
0
 /// <summary>
 /// Stops server.
 /// </summary>
 public override void Stop()
 {
     if (ServerStatus == SocketServerStatus.Stop)
     {
         return;
     }
     ServerStatus = SocketServerStatus.Stop;
 }
예제 #3
0
 /// <summary>
 /// Runs server with specified befor IP and Port.
 /// </summary>
 public override void Start()
 {
     if (ServerStatus != SocketServerStatus.Stop)
     {
         return;
     }
     ServerStatus = SocketServerStatus.Start;
     ReceiveData();
 }
예제 #4
0
 /// <summary>
 /// Runs server with specified befor IP and Port.
 /// </summary>
 public override void Start()
 {
     if (ServerStatus != SocketServerStatus.Stop)
     {
         return;
     }
     ServerStatus = SocketServerStatus.Start;
     AcceptConnections();
 }
예제 #5
0
        public void ListenBind(int port)
        {
            IPAddress ipaddr = IPAddress.Any;

            try
            {
                server.NoDelay = true;
                server.Bind(new IPEndPoint(ipaddr, port));
                status = SocketServerStatus.Binded;
                server.Listen(10);
                status = SocketServerStatus.Listened;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #6
0
 /// <summary>
 /// Stops server.
 /// </summary>
 public override void Stop()
 {
     if (ServerStatus == SocketServerStatus.Stop)
     {
         return;
     }
     ServerStatus = SocketServerStatus.Stop;
     _listener.Stop();
     while (SocketClients.Count > 0)
     {
         var socketClient = SocketClients[0];
         socketClient.Disconnect();
         if (SocketClients.Contains(socketClient))
         {
             SocketClients.Remove(socketClient);
         }
     }
 }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SocketDatagramServer"/> class with specified local point.
 /// </summary>
 /// <param name="port">The port of local host.</param>
 public SocketDatagramServer(Int32 port)
 {
     _client       = new UdpClient(port);
     LocalEndPoint = (IPEndPoint)_client.Client.LocalEndPoint;
     ServerStatus  = SocketServerStatus.Stop;
 }