예제 #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
파일: COVER.cs 프로젝트: dwickeroth/covise
        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
파일: COVER.cs 프로젝트: dwickeroth/covise
        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);
        }