Example #1
0
        bool processMessage(cBaseMessage i_cbm)
        {
            switch (i_cbm.getMsgType())
            {
                case NW_MSG_TYPE.WELCOME:
                    m_PlayerID = i_cbm.getPlayerID();
                    if(m_PlayerID != 0)
                        m_ConnectedToServer = true;
                    break;

                case NW_MSG_TYPE.PING:
                    //we got a ping, do nothing, hope sendData answers
                    break;
            }

            //ACK this one
            sendData(new cAckMessage(m_PlayerID));

            return true;
        }
Example #2
0
        public void sendData(cBaseMessage cbm)
        {
            if (m_ClientSocket.Connected)
            {
                m_ClientSocket.Send(cbm.asArray());

                if (m_SockSide == eSocketSide.SERVER)
                { //Server sent this one
                    setIsAck(false); //wait for ack
                }
            }
        }
Example #3
0
        void onDataInput(IAsyncResult res)
        {
            cGameClient recieveSocket = (cGameClient)res.AsyncState;
            int recBytes = recieveSocket.getSocket().EndReceive(res);
            byte[] InputBuffer = recieveSocket.getBuffer();

            cBaseMessage IncomingMessage = new cBaseMessage(InputBuffer);
            processMessage(IncomingMessage);

            //wait again for data
            recieveSocket.getSocket().BeginReceive(getBuffer(), 0, 255, System.Net.Sockets.SocketFlags.None, onDataInput, this);
        }