Exemplo n.º 1
0
 public void readSocket()
 {
     if (!socketReady)
     {
         return;
     }
     if (theStream != null && theStream.DataAvailable)
     {
         byte[] buffer = new byte[2];
         theStream.Read(buffer, 0, 2);
         short bufferSize = BitConverter.ToInt16(buffer, 0);
         buffer = new byte[bufferSize];
         theStream.Read(buffer, 0, bufferSize);
         MemoryStream    dataStream  = new MemoryStream(buffer);
         short           response_id = DataReader.ReadShort(dataStream);
         NetworkResponse response    = NetworkResponseTable.get(response_id);
         if (response != null)
         {
             response.dataStream = dataStream;
             response.parse();
             ExtendedEventArgs args = response.process();
             if (args != null)
             {
                 MessageQueue msgQueue = mainObject.GetComponent <MessageQueue>();
                 msgQueue.AddMessage(args.event_id, args);
             }
         }
     }
 }
    public void readSocket()
    {
        if (!socketReady)
        {
            return;
        }
        int count = 0;

        while (count < sockets.Count)
        {
            try
            {
                theStream = sockets[count].GetStream();
                if (theStream != null && theStream.DataAvailable)
                {
                    byte[] buffer = new byte[2];
                    theStream.Read(buffer, 0, 2);
                    short bufferSize = BitConverter.ToInt16(buffer, 0);
                    buffer = new byte[bufferSize];
                    theStream.Read(buffer, 0, bufferSize);
                    MemoryStream    dataStream  = new MemoryStream(buffer);
                    short           response_id = DataReader.ReadShort(dataStream);
                    NetworkResponse response    = NetworkResponseTable.get(response_id);
                    if (response != null)
                    {
                        response.dataStream = dataStream;
                        response.parse();
                        ExtendedEventArgs args = response.process();
                        if (args != null)
                        {
                            MessageQueue msgQueue = mainObject.GetComponent <MessageQueue>();
                            msgQueue.AddMessage(args.event_id, args);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debug.Log("Stream error: " + e);
            }
            count++;
        }
    }