示例#1
0
        public void handleMessages()
        {
            if (toCOVER != null)
            {
                Byte[] data = new Byte[2000];
                while (true)
                {
                    int len = 0;
                    while (len < 16)
                    {
                        int numRead;
                        try
                        {
                            numRead = toCOVER.GetStream().Read(data, len, 16 - len);
                        }
                        catch (System.IO.IOException e)
                        {
                            // probably socket closed
                            return;
                        }
                        len += numRead;
                    }

                    int msgType = BitConverter.ToInt32(data, 2 * 4);
                    int length  = BitConverter.ToInt32(data, 3 * 4);
                    length  = (int)ByteSwap.swap((uint)length);
                    msgType = (int)ByteSwap.swap((uint)msgType);
                    len     = 0;
                    while (len < length)
                    {
                        int numRead;
                        try
                        {
                            numRead = toCOVER.GetStream().Read(data, len, length - len);
                        }
                        catch (System.IO.IOException e)
                        {
                            // probably socket closed
                            return;
                        }
                        len += numRead;
                    }
                    COVERMessage m = new COVERMessage(new MessageBuffer(data), msgType);
                    messageQueue.Enqueue(m);
                }
            }
        }
示例#2
0
        public bool checkForMessages()
        {
            int len = 0;
              Byte[] data = new Byte[16];

              while (len < 16)
              {
              int numRead;
              try
              {
                  if (toCOVER != null)
                  {
                      //toCOVER.GetStream().ReadTimeout = 10;
                      numRead = toCOVER.GetStream().Read(data, len, 16 - len);
                      if (numRead == 0 && len == 0)
                          return false;
                  }
                  else
                  {
                      return false;
                  }
              }
              catch (System.IO.IOException e)
              {
                  toCOVER = null;
                  // probably socket closed
                  return false;
              }
              catch (System.InvalidOperationException e)
              {
                  toCOVER = null;
                  // probably socket closed
                  return false;
              }
              len += numRead;
              }

              int msgType = BitConverter.ToInt32(data, 2 * 4);
              int length = BitConverter.ToInt32(data, 3 * 4);
              length = (int)ByteSwap.swap((uint)length);
              msgType = (int)ByteSwap.swap((uint)msgType);

              data = new Byte[length];
              len = 0;
              while (len < length)
              {
              int numRead;
              try
              {
                  numRead = toCOVER.GetStream().Read(data, len, length - len);
              }
              catch (System.IO.IOException e)
              {
                  // probably socket closed
                  return false;
              }
              len += numRead;
              }
              COVERMessage m = new COVERMessage(new MessageBuffer(data), msgType);
              messageQueue.Enqueue(m);
              return true;
        }
示例#3
0
        public void handleMessages()
        {
            if (toCOVER != null)
              {
              Byte[] data = new Byte[2000];
              while (true)
              {
                  int len = 0;
                  while (len < 16)
                  {
                      int numRead;
                      try
                      {
                          numRead = toCOVER.GetStream().Read(data, len, 16 - len);
                      }
                      catch (System.IO.IOException e)
                      {
                          // probably socket closed
                          return;
                      }
                      len += numRead;
                  }

                  int msgType = BitConverter.ToInt32(data, 2 * 4);
                  int length = BitConverter.ToInt32(data, 3 * 4);
                  length = (int)ByteSwap.swap((uint)length);
                  msgType = (int)ByteSwap.swap((uint)msgType);
                  len = 0;
                  while (len < length)
                  {
                      int numRead;
                      try
                      {
                          numRead = toCOVER.GetStream().Read(data, len, length - len);
                      }
                      catch (System.IO.IOException e)
                      {
                          // probably socket closed
                          return;
                      }
                      len += numRead;
                  }
                  COVERMessage m = new COVERMessage(new MessageBuffer(data), msgType);
                  messageQueue.Enqueue(m);
              }
              }
        }
示例#4
0
        public bool checkForMessages()
        {
            int len = 0;

            Byte[] data = new Byte[16];

            while (len < 16)
            {
                int numRead;
                try
                {
                    if (toCOVER != null)
                    {
                        //toCOVER.GetStream().ReadTimeout = 10;
                        numRead = toCOVER.GetStream().Read(data, len, 16 - len);
                        if (numRead == 0 && len == 0)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch (System.IO.IOException e)
                {
                    toCOVER = null;
                    // probably socket closed
                    return(false);
                }
                catch (System.InvalidOperationException e)
                {
                    toCOVER = null;
                    // probably socket closed
                    return(false);
                }
                len += numRead;
            }

            int msgType = BitConverter.ToInt32(data, 2 * 4);
            int length  = BitConverter.ToInt32(data, 3 * 4);

            length  = (int)ByteSwap.swap((uint)length);
            msgType = (int)ByteSwap.swap((uint)msgType);

            data = new Byte[length];
            len  = 0;
            while (len < length)
            {
                int numRead;
                try
                {
                    numRead = toCOVER.GetStream().Read(data, len, length - len);
                }
                catch (System.IO.IOException e)
                {
                    // probably socket closed
                    return(false);
                }
                len += numRead;
            }
            COVERMessage m = new COVERMessage(new MessageBuffer(data), msgType);

            messageQueue.Enqueue(m);
            return(true);
        }