private void ClientConnected(object sender, AsyncCarClientToken e) { if (GetInputCommandFactory == null) return; var commandFactory = GetInputCommandFactory(); var cp = new TextAuthProto(e, commandFactory, _nextId++, _carService); e.Proto = cp; _cars.Add(cp.Id, cp); }
private void ProcessAccept(SocketAsyncEventArgs e) { Interlocked.Increment(ref _numConnectedSockets); // Get the socket for the accepted client connection and put it into the //ReadEventArg object user token var readEventArgs = new SocketAsyncEventArgs(); var buf = new byte[ReceiveBufferSize]; readEventArgs.Completed += IO_Completed; readEventArgs.SetBuffer(buf, 0, ReceiveBufferSize); var token = new AsyncCarClientToken(readEventArgs, this); readEventArgs.UserToken = token; token.Socket = e.AcceptSocket; OnClientConnected(token); // As soon as the client is connected, post a receive to the connection bool willRaiseEvent = e.AcceptSocket.ReceiveAsync(readEventArgs); if (!willRaiseEvent) { ProcessReceive(readEventArgs); } // Accept the next connection request StartAccept(e); }
protected virtual void OnClientDisonnected(AsyncCarClientToken e) { ClientDisonnected?.Invoke(this, e); }
private void ClientDisconnected(object sender, AsyncCarClientToken e) { _cars.Remove(e.Proto.Id); OnClientDisconnected?.Invoke(); }