Exemplo n.º 1
0
 private TcpTalk GetTalker(string connectionId, TcpAddress destination)
 {
     lock (_talkers)
     {
         TcpTalk talker;
         if (!_talkers.TryGetValue(connectionId, out talker))
         {
             talker = new TcpTalk(_port, destination);
             talker.HandleMessage(HandleMessage);
             _talkers[connectionId] = talker;
         }
         return talker;
     }
 }
Exemplo n.º 2
0
 private void HandleMessage(byte[] data, TcpTalk talker)
 {
     if (_handleMessage != null)
     {
         var message = Message.Deserialise(data);
         var connectionId = message.ConnectionId.GetString();
         if (!string.IsNullOrEmpty(connectionId))
         {
             if (!_talkers.ContainsKey(connectionId))
             {
                 _talkers[connectionId] = talker;
             }
             _handleMessage(message, talker.Destination);
         }
     }
 }
Exemplo n.º 3
0
 private void Send(TcpTalk talker, byte[] data)
 {
     var send = new Task(() =>
     {
         lock (talker)
         {
             talker.SendData(data);
         }
     });
     send.Start();
 }
Exemplo n.º 4
0
 private void NewClientConnection(TcpClient client)
 {
     lock (_talkers)
     {
         var talker = new TcpTalk(client);
         talker.HandleMessage(HandleMessage);
     }
 }