Beispiel #1
0
        public void sendPacket(PacketInterface packet)
        {
            try {
                packet.encode();
                MemoryStream packetBlock = new MemoryStream();

                Int32 packetLen = sizeof(Int32) + (Int32)packet.getStream().Length;

                Byte[] packetHeader = BitConverter.GetBytes(packetLen);
                PacketObfuscation.encodingHeader(ref packetHeader, (int)packetHeader.Length);
                packetBlock.Write(packetHeader, 0, (Int32)packetHeader.Length);

                Byte[] packetData = packet.getStream().ToArray();
                PacketObfuscation.encodingData(ref packetData, (int)packetData.Length);
                packetBlock.Write(packetData, 0, (Int32)packetData.Length);

                Byte[] packetBytes = packetBlock.ToArray();
                stream_.Write(packetBytes, 0, (int)packetBlock.Length);
                stream_.Flush();

                packetBlock = null;
            } catch (Exception e) {
                if (this.isConnected())
                {
                    MessageBox.Show("잘못된 처리 : " + e.ToString(), "error", MessageBoxButtons.OK);
                    Application.Exit();
                }
            }
        }
Beispiel #2
0
        public void sendPacket(Packetinterface packet)
        {
            try
            {
                packet.encode();
                //Header -> data 순으로 바이트변환후 packet내 외부스트림에 저장
                MemoryStream packetBlock = new MemoryStream();
                Int32        packetLen   = sizeof(Int32) + (Int32)packet.getStream().Length;

                Byte[] packetHeader = BitConverter.GetBytes(packetLen);
                //packetHeader는 Packet의 총길이
                PacketObfuscation.encodingHeader(ref packetHeader, (int)packetHeader.Length);
                //길이 암호화
                packetBlock.Write(packetHeader, 0, (Int32)packetHeader.Length);


                Byte[] packetData = packet.getStream().ToArray();

                PacketObfuscation.encodingData(ref packetData, (int)packetData.Length);

                packetBlock.Write(packetData, 0, (Int32)packetData.Length);
                //실데이터 암호화후 블럭에 넣음

                Byte[] packetBytes = packetBlock.ToArray();
                // 블럭을 바이트로 변환
                stream_.Write(packetBytes, 0, (int)packetBlock.Length);

                stream_.Flush();
                packetBlock = null;
            }catch (Exception e)
            {
                if (this.isConnected())
                {
                    Debug.Log("잘못된 처리 : send " + e.ToString());
                }
            }
        }