private void EndAccepting(IAsyncResult result) { var client = new Client(InternalSocket.EndAccept(result)); client.StartReceive(); InternalSocket.BeginAccept(EndAccepting, null); }
public void Listen(int port) { InternalSocket.Bind(new IPEndPoint(IPAddress.Any, port)); InternalSocket.Listen(100); InternalSocket.BeginAccept(AcceptCallback, this); }
public void Listen(IPEndPoint hostEndPoint) { InternalSocket.Bind(hostEndPoint); InternalSocket.Listen(100); InternalSocket.BeginAccept(AcceptCallback, this); }
private void AcceptCallback(IAsyncResult ar) { var socketObject = new SocketObject(InternalSocket.EndAccept(ar)); if (SocketConnected != null) { SocketConnected(socketObject); } socketObject.BeginReceive(this); InternalSocket.BeginAccept(AcceptCallback, this); }
public void Start() { try { InternalSocket.Bind(ServerEndPoint); InternalSocket.Listen(500); InternalSocket.BeginAccept(EndAccepting, null); } catch (SocketException ex) { if (ex.ErrorCode == (int)SocketError.AddressAlreadyInUse) { throw new InvalidOperationException("The selected port is already used by another process"); } throw new NotSupportedException("oops unexpected error was thrown please report this issue to the developer."); } }