示例#1
0
        /// <summary>
        /// Send a message to the remote node.
        /// </summary>
        /// <param name="tcpClient">The TcpClient for communication with the remote node</param>
        /// <param name="message">The NetworkRequest to send to the remote node</param>
        /// <returns>The number of bytes written to the remote node or -1 if an error occurred.</returns>
        private int sendMessage(TcpClient tcpClient, NetworkEvent message)
        {
            Logger.Debug("ClientThread:sendMessage");
            MemoryStream mem = new MemoryStream();

            binaryFormatter.Serialize(mem, message);
            byte[] bytes = mem.ToArray();
            int    num   = bytes.Length;

            byte[] numBytes = BitConverter.GetBytes((ushort)num);
            int    ret      = writeBytes(tcpClient, numBytes, MESSAGE_SIZE_SIZE);

            if (ret == -1)
            {
                Logger.Error("ClientThread:sendMessage failed to send message size");
            }
            ret = writeBytes(tcpClient, bytes, num);
            if (ret == -1)
            {
                Logger.Error("ClientThread:sendMessage failed to send a message");
            }
            return(ret);
        }
示例#2
0
 protected void processNetworkEvent(ClientThread ct, NetworkEvent ne)
 {
     Logger.Debug("EchoBackupService:processNetworkEvent");
     if (ne is NetworkResponse)
     {
         processNetworkResponse(ct, (NetworkResponse)ne);
     }
     else if (ne is QueryRequest)
     {
         processQueryRequest(ct, (QueryRequest)ne);
     }
     else if (ne is PushRequest)
     {
         processPushRequest(ct, (PushRequest)ne);
     }
     else if (ne is PullRequest)
     {
         processPullRequest(ct, (PullRequest)ne);
     }
     else if (ne is PushIndexRequest)
     {
         processPushIndexRequest(ct, (PushIndexRequest)ne);
     }
 }
示例#3
0
 protected void checkClientThreads()
 {
     lock (clientThreads)
     {
         //foreach (ClientThread thread in clientThreads)
         for (int i = 0; i < clientThreads.Count; i++)
         {
             if (clientThreads[i].EventCount() > 0)
             {
                 NetworkEvent ne = clientThreads[i].DequeueEvent();
                 processNetworkEvent(clientThreads[i], ne);
             }
             else
             {
                 if (clientThreads[i].IsAlive() == false)
                 { //remove dead threads with empty event queues from the list
                     clientThreads.RemoveAt(i);
                     i--;
                     continue;
                 }
             }
         }
     }
 }
示例#4
0
 /// <summary>
 /// Send a message to the remote node.
 /// </summary>
 /// <param name="tcpClient">The TcpClient for communication with the remote node</param>
 /// <param name="message">The NetworkRequest to send to the remote node</param>
 /// <returns>The number of bytes written to the remote node or -1 if an error occurred.</returns>
 private int sendMessage(TcpClient tcpClient, NetworkEvent message)
 {
     Logger.Debug("ClientThread:sendMessage");
     MemoryStream mem = new MemoryStream();
     binaryFormatter.Serialize(mem, message);
     byte[] bytes = mem.ToArray();
     int num = bytes.Length;
     byte[] numBytes = BitConverter.GetBytes((ushort)num);
     int ret = writeBytes(tcpClient, numBytes, MESSAGE_SIZE_SIZE);
     if (ret == -1)
     {
         Logger.Error("ClientThread:sendMessage failed to send message size");
     }
     ret = writeBytes(tcpClient, bytes, num);
     if (ret == -1)
     {
         Logger.Error("ClientThread:sendMessage failed to send a message");
     }
     return ret;
 }
示例#5
0
 protected void processNetworkEvent(ClientThread ct, NetworkEvent ne)
 {
     Logger.Debug("EchoBackupService:processNetworkEvent");
     if (ne is NetworkResponse)
     {
         processNetworkResponse(ct, (NetworkResponse)ne);
     }
     else if (ne is QueryRequest)
     {
         processQueryRequest(ct, (QueryRequest)ne);
     }
     else if (ne is PushRequest)
     {
         processPushRequest(ct, (PushRequest)ne);
     }
     else if (ne is PullRequest)
     {
         processPullRequest(ct, (PullRequest)ne);
     }
     else if (ne is PushIndexRequest)
     {
         processPushIndexRequest(ct, (PushIndexRequest)ne);
     }
 }