public override void Execute() { ClientConnection client = ConnectionRepository.Instance.Query(c => c.ClientId == _clientId).FirstOrDefault(); if (client != null) { ResponseHeader responseHeader = ResponseBuilder.BuildResponseHeader(_encryptionType, _compressionType, _responseType); ZipSocket connection = SocketRepository.Instance.FindByClientId(_clientId); if (connection != null) { connection.SendData( XmlSerializationHelper .Serialize <ResponseHeader>(responseHeader) .SerializeUTF()); //connection.SendData( // ResponseBuilder.ProcessResponse( // client.ServerAuthority, // client // .RequestHeader // .MessageHeader // .EncryptionHeader // .PublicKey, // responseHeader, // _response).SerializeUTF()); } } }
public override void Execute() { ZipSocket connection = SocketRepository.Instance.FindByClientId(_clientId); if (connection != null) { connection.SendData(_message.SerializeUTF()); } }
public override void Execute() { ZipSocket rawSocket = SocketRepository.Instance.FindByClientId(_clientId); if (rawSocket != null) { Connection connection = ConnectionRepository.Instance.FindConnectionByClientId(_clientId); if (connection != null) { connection.ConnectionState = ConnectionState.NegotiateKeyPair; } } }
/// <summary> /// Adds the socket. /// </summary> /// <param name="clientId">The client id.</param> /// <param name="connection">The connection.</param> public ZipSocket AddSocket(Guid clientId, Socket connection) { _connectionMutex.WaitOne(); try { ZipSocket socket = new ZipSocket(connection); _connectionList.Add(clientId, socket); return(socket); } finally { _connectionMutex.ReleaseMutex(); } }
/// <summary> /// Connects the specified address. /// </summary> /// <param name="address">The address.</param> /// <param name="port">The port.</param> public void Connect(string address, int port) { if (!_connected) { var rawSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _serverDisconnectedEvent.Reset(); bool connected = false; while (!connected) { try { rawSocket.Connect(address, port); connected = true; } catch (SocketException se) { OnConnectionResponse(new ConnectionEventArgs { IsSuccessful = false }); return; } } // wrap the socket _socket = new ZipSocket(rawSocket); if (!NegotiateKeys()) { // we could not negotiate keys, so we can't connect OnConnectionResponse(new ConnectionEventArgs { IsSuccessful = false }); } else { OnConnectionResponse(new ConnectionEventArgs { IsSuccessful = true }); _connected = true; // start pumping messages var serverThread = new Thread(PumpMessages); serverThread.Start(); } } }