Example #1
0
        protected void DoProcessReceivedBuffer()
        {
            if (myReceiveBuffer.Length == 0)
            {
                return;
            }
            //Console.Error.WriteLine($"DoProcessReceivedBuffer {myReceiveBuffer.Length}");
            int terminatorIdx;

            while ((myReceiveBuffer.Length > 0) && ((terminatorIdx = myReceiveBuffer.IndexOf('\n')) >= 0))
            {
                string msg1 = myReceiveBuffer.Substring(0, terminatorIdx); // without the terminator
                myReceiveBuffer = myReceiveBuffer.Substring(terminatorIdx + 1);
                //cout << "Incoming message: from " << myPeerAddr << " '" << msg1 << "' " << myReceiveBuffer.length() << endl;
                // split into tokens
                string[]    tokens = msg1.Split(' ');
                BaseMessage msg    = MessageDeserializer.ParseMessage(tokens);
                if (msg == null)
                {
                    Console.Error.WriteLine($"Error: Unparseable message '{msg1}' {tokens.Length}");
                    continue;
                }
                myState = State.Received;
                System.Diagnostics.Debug.Assert(myApp != null);
                myApp.MessageReceived(this, msg);
            }
        }