Ejemplo n.º 1
0
    public void OnSendData(string message)
    {
        Debug.Log("OnSendData");
        if (testIndex >= UInt32.MaxValue)
        {
            testIndex = 0;
        }
        byte[] buff = null;
        if (testIndex % 2 == 0)
        {
            PacketRoundInfo sendPacket = new PacketRoundInfo((int)PacketType.ROUND_INFO);
            sendPacket.InitPacketRoundInfo();
            buff = sendPacket.ToBytes();
        }
        else
        {
            PacketUserInfo sendPacket = new PacketUserInfo((int)PacketType.USER_INFO);
            sendPacket.InitPacketUserInfo();
            buff = sendPacket.ToBytes();
        }
        _mainSock.Send(buff);
        testIndex++;

        if (SendUpdate != null)
        {
            //SendUpdate(buff);
        }
    }
Ejemplo n.º 2
0
    private void ProcessPacket()
    {
        if (_packetQueue.Count <= 0)
        {
            return;
        }

        Packet packet = _packetQueue.Dequeue();

        if (packet.PacketType.n == (int)PacketType.USER_INFO)
        {
            PacketUserInfo userInfo = packet as PacketUserInfo;

            if (userInfo != null)
            {
                ReceiveCallBack(userInfo);
            }
        }
        else if (packet.PacketType.n == (int)PacketType.ROUND_INFO)
        {
            PacketRoundInfo roundInfo = packet as PacketRoundInfo;
            if (roundInfo != null)
            {
                ReceiveCallBack(roundInfo);
            }
        }
    }
Ejemplo n.º 3
0
        private void ProcessPacket()
        {
            if (_packetQueue.Count <= 0)
            {
                return;
            }

            Packet packet = _packetQueue.Dequeue();

            AsyncObject obj = new AsyncObject(BufferSize);

            if (packet.PacketType.n == (int)PacketType.USER_INFO)
            {
                PacketUserInfo userInfo = packet as PacketUserInfo;

                if (userInfo != null)
                {
                    ProcessSendMessage(userInfo);
                }
            }
            else if (packet.PacketType.n == (int)PacketType.ROUND_INFO)
            {
                PacketRoundInfo roundInfo = packet as PacketRoundInfo;

                if (roundInfo != null)
                {
                    ProcessSendMessage(roundInfo);
                }
            }
        }
    private void TestPacket()
    {
        PacketUserInfo sendPacket = new PacketUserInfo((int)PacketType.USER_INFO);

        sendPacket.InitPacketUserInfo();

        Debug.Log(sendPacket.ToString());
        byte[] buff = sendPacket.ToBytes();

        PacketUserInfo receivePacket = new PacketUserInfo((int)PacketType.USER_INFO);

        receivePacket.ToType(buff);
        Debug.Log(receivePacket.ToString());
    }
Ejemplo n.º 5
0
        private void ProcessStreamByte()
        {
            if (_byteList.Count < 2) // 패킷사이즈도 알아 낼수 없는 경우
            {
                return;
            }

            if (_packetSize == 0)
            {
                byte[] sizeByte = new byte[2];
                sizeByte[0] = _byteList[0];
                sizeByte[1] = _byteList[1];
                _packetSize = Util.ByteArrToShort(sizeByte, 0);
            }

            if (_byteList.Count < _packetSize) // 필요한 만큼 다 못 받은 경우
            {
                return;
            }
            else
            {
                byte[] packetByte = new byte[_packetSize];

                for (int i = 0; i < _packetSize; i++)
                {
                    packetByte[i] = _byteList[i];
                }

                _byteList.RemoveRange(0, _packetSize);
                int packetType = Util.ByteArrToInt(packetByte, 2);

                if (packetType == (int)PacketType.USER_INFO)
                {
                    PacketUserInfo userInfo = new PacketUserInfo(packetType);
                    userInfo.ToType(packetByte);
                    _packetQueue.Enqueue(userInfo);
                }
                else if (packetType == (int)PacketType.ROUND_INFO)
                {
                    PacketRoundInfo roundInfo = new PacketRoundInfo(packetType);
                    roundInfo.ToType(packetByte);
                    _packetQueue.Enqueue(roundInfo);
                }

                _packetSize = 0;
            }
            ProcessPacket();
        }