コード例 #1
0
        private void RecieveMessages()
        {
            if (stream.DataAvailable)
            {
                short msgId = ShittyNetUtility.ReadShort(stream);
                switch (msgId)
                {
                case 0:     //ping
                    lastPingRecieved = 0;
                    break;

                case 1:     //sensor data
                    Msg_In_SensorData msg = new Msg_In_SensorData();
                    msg.ReadMessage(stream);
                    messagesIn.Add(msg);
                    break;

                case 2:
                    Console.WriteLine("completed");
                    messagesIn.Add(new Msg_In_Complete());
                    break;

                default:
                    Console.WriteLine("unknown message!");
                    break;
                }
            }
        }
コード例 #2
0
 private void SendPing()
 {
     lastPingSended += (int)stopwatch.ElapsedMilliseconds;
     try
     {
         if (lastPingSended > 100)
         {
             ShittyNetUtility.WriteShort(0, stream);
             lastPingSended = 0;
         }
     }
     catch (Exception e)
     {
     }
 }