protected void AddClient(ClientConnection connection) { lock (connectionListLock) { connectionList.Add(connection); } }
private string ProcessRawRequest(ClientConnection client, string requestString) { if (client.RequestHeader.MessageHeader.CompressionType != CompressionTypes.None) { // decompress } if (client.RequestHeader.MessageHeader.EncryptionHeader.EncryptionType != EncryptionTypes.None) { // decrypt //byte [] publicKeyEncoded = client.RequestHeader.MessageHeader.EncryptionHeader.PublicKey; //DHPublicKeyParameters publicKey = new DHPublicKeyParameters( // ((DHPublicKeyParameters)PublicKeyFactory.CreateKey(publicKeyEncoded)).Y, client.ServerAuthority.Parameters); //BigInteger agreementValue = client.ServerAuthority.GenerateAgreementValue(publicKey); //RijndaelCrypto crypto = new RijndaelCrypto(); //return crypto.Decrypt(requestString, agreementValue.ToString(16)); } return requestString; }
public static ClientConnection CreateClientConnection(MessageEnvelope envelope, INetworkTransport client) { ClientConnection connection = new ClientConnection(envelope, client); connection.StartReceiveThread(); return connection; }
static void Main(string[] args) { Thread.Sleep(2000); Console.Write("Connecting to ChannelListener..."); ClientConnection client = new ClientConnection(new PlainEnvelope(), new SocketTransport()); //TcpClient client = new TcpClient(); //client.Connect("localhost", port); client.ClientClosed += new EventHandler<DisconnectedArgs>(client_ClientClosed); client.MessageReceived += new EventHandler<MessageEventArgs>(client_MessageReceived); client.Connect("localhost", port); Console.WriteLine("connected!"); DateTime connectTime = DateTime.Now; Console.WriteLine(string.Format("Connected at {0}", connectTime)); int count = 1; while (true) { Dictionary<string, string> headers = new Dictionary<string, string>(); string command = ""; while (true) { command = Console.ReadLine(); headers.Clear(); while (true) { string line = Console.ReadLine(); // check for termination if (line.Length == 0) break; string[] pieces = line.Split(':'); headers.Add(pieces[0].ToUpper(), pieces[1].ToUpper()); } break; } MessageOne msg = new MessageOne(); msg.MessageID = "MessageOne"; msg.Value = 23; //scm.ControlMode = ControlMode.ChannelController; try { var env = client.Envelope; using (StreamWrapper wrapper = new StreamWrapper(client.Transport.Stream)) { env.Serialize(msg, wrapper); //((SocketTransport)client.Transport) //IMessage response = client.Send<Message>(msg); //Console.WriteLine(msg.Name); } } catch (Exception pex) { Console.WriteLine(pex.Message); } //CustomMessage message = new CustomMessage(command); //foreach (string key in headers.Keys) // message.AddKeyValue(key, headers[key]); //Message response; //{ // try // { // response = client.SendAndReceive(message); // Console.WriteLine("Message received: " + response.Name); // Console.WriteLine(response.ToString()); // } // catch (Exception ex) // { // Console.WriteLine(ex.Message + "\r\n"); // Console.WriteLine("Reconnecting..."); // Console.WriteLine(client.Connect()); // connectTime = DateTime.Now; // Console.WriteLine(string.Format("Connected at {0}", connectTime)); // } //} TimeSpan ts = DateTime.Now - connectTime; Console.WriteLine(string.Format(" connection open for {0:D2}:{1:D2}:{2:D2} [{3} messages processed]\r\n", ts.Hours, ts.Minutes, ts.Seconds, count++)); } }
public MessageEventArgs(ClientConnection source, IMessage message, byte[] raw) { ClientConnection = source; Message = message; RawMessage = raw; }
protected virtual void OnClientConnected(Guid clientId, ClientConnection connection, string remoteAddress) { EventHandler<ConnectArgs> clientConnected = ClientConnected; if (clientConnected != null) { var args = new ConnectArgs(clientId, connection, remoteAddress); clientConnected(this, args); } }
/// <summary> /// Initializes a new instance of the <see cref="ConnectArgs"/> class. /// </summary> /// <param name="clientId">The client id.</param> /// <param name="rawSocket">The raw socket.</param> /// <param name="remoteAddress">The remote address.</param> public ConnectArgs(Guid clientId, ClientConnection connection, string remoteAddress) { ClientId = clientId; RemoteAddress = remoteAddress; Connection = connection; }
public MessageEventArgs(ClientConnection source, IMessage message, byte[] raw) { ClientConnection = source; Message = message; RawMessage = raw; }
/// <summary> /// Finds the connection by client id. /// </summary> /// <param name="clientId">The client id.</param> /// <returns></returns> //public ClientConnection FindConnectionByClientId(Guid clientId) //{ // _connectionMutex.WaitOne(); // try // { // IEnumerable<ClientConnection> q = from c in _connectionList // where c.ClientId == clientId // select c; // return q.FirstOrDefault(); // } // finally // { // _connectionMutex.ReleaseMutex(); // } //} /// <summary> /// Removes the connection. /// </summary> /// <param name="connection">The connection.</param> public void RemoveConnection(ClientConnection connection) { _connectionMutex.WaitOne(); try { _connectionList.Remove(connection); } finally { _connectionMutex.ReleaseMutex(); } }
/// <summary> /// Initializes a new instance of the <see cref="ConnectArgs"/> class. /// </summary> /// <param name="clientId">The client id.</param> /// <param name="rawSocket">The raw socket.</param> /// <param name="remoteAddress">The remote address.</param> public ConnectArgs(Guid clientId, ClientConnection connection, string remoteAddress) { ClientId = clientId; RemoteAddress = remoteAddress; Connection = connection; }