/// <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; }
/// <summary> /// Stops server. /// </summary> public override void Stop() { if (ServerStatus == SocketServerStatus.Stop) { return; } ServerStatus = SocketServerStatus.Stop; }
/// <summary> /// Runs server with specified befor IP and Port. /// </summary> public override void Start() { if (ServerStatus != SocketServerStatus.Stop) { return; } ServerStatus = SocketServerStatus.Start; ReceiveData(); }
/// <summary> /// Runs server with specified befor IP and Port. /// </summary> public override void Start() { if (ServerStatus != SocketServerStatus.Stop) { return; } ServerStatus = SocketServerStatus.Start; AcceptConnections(); }
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; } }
/// <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); } } }
/// <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; }