Esempio n. 1
0
        void ProcessMessage(IPEndPoint their_addr, Stream stm, MessageType mt)
        {
            if (mt == MessageType.MESSAGE)
            {
                string msg = (string)SocketReader.ReadSerializedMessage(stm);

                processQueue(() => this.Sync_NewMessage(this.NodeByEP(their_addr), msg));
            }
            else if (mt == MessageType.NAME)
            {
                string msg = (string)SocketReader.ReadSerializedMessage(stm);

                processQueue(() => this.Sync_NewName(this.NodeByEP(their_addr), msg));
            }
            else if (mt == MessageType.TABLE_REQUEST)
            {
                processQueue(() => this.Sync_TableRequest(this.NodeByEP(their_addr)));
            }
            else if (mt == MessageType.TABLE)
            {
                var table = (IPEndPoint[])SocketReader.ReadSerializedMessage(stm);
                processQueue(() => this.Sync_OnTable(table));
            }
            else
            {
                throw new InvalidOperationException("Unexpected message type " + mt.ToString());
            }
        }
Esempio n. 2
0
        public static void ConnectionHandshake(Socket sckRead, Action <Handshake, Socket> processConnection)
        {
            using (NetworkStream connectionStream = new NetworkStream(sckRead, false))
            {
                int nTp = connectionStream.ReadByte();

                if (nTp != (int)MessageType.HANDSHAKE)
                {
                    Console.WriteLine("Invalid incoming connection message (expecting handshake): type {0} {1}", nTp, (MessageType)nTp);
                    return;
                }

                Handshake their_info = (Handshake)SocketReader.ReadSerializedMessage(connectionStream);

                processConnection(their_info, sckRead);
            }
        }