Example #1
0
        public static NetworkResponse get(short response_id)
        {
            NetworkResponse response = null;

//		Debug.Log("Response table: " + responseTable[response_id].ToString());

            if (responseTable.ContainsKey(response_id))
            {
                response             = (NetworkResponse)Activator.CreateInstance(responseTable[response_id]);
                response.response_id = response_id;
            }
            else
            {
                Debug.Log("Response [" + response_id + "] Not Found");
                Debug.Log(response.ToString());
            }

            return(response);
        }
        public void ReadSocket()
        {
            if (!socketReady)
            {
                return;
            }

            if (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);
                Debug.Log("response_id: " + response_id);
                //Debug.Log(response_id.GetType().ToString());
                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);
                    }
                }
            }
        }