Exemplo n.º 1
0
    public void Sendn(ref DataPacketString message)
    {
        CReadyNetWork netWork = CReadyNetWork.GetInstance();
        NetworkStream stream  = netWork.GetStream();

        try
        {
            byte[] sizeBuffer = new byte[ConstVaue.IntSize];

            DataPacketInt size = new DataPacketInt(message.GetStrLen());
            Serialize(size, ref sizeBuffer);

            stream.Write(sizeBuffer, 0, ConstVaue.IntSize);

            byte[] messageBuffer = new byte[ConstVaue.BufSize];
            Serialize(message, ref messageBuffer);

            stream.Write(messageBuffer, 0, message.GetStrLen());
        }
        catch (Exception e)
        {
            Debug.Log(e.Message);
            message.Message = "Exception";
        }
    }
Exemplo n.º 2
0
    public void Listen()
    {
        while (true)
        {
            try
            {
                mMessage.Message = "";
                byte[] sizeBuffer = new byte[ConstVaue.IntSize];
                int    isSuccess  = mStream.Read(sizeBuffer, 0, ConstVaue.IntSize);

                DataPacketInt size = new DataPacketInt();
                Deserialize(ref size, ref sizeBuffer);

                byte[] messageBuffer = new byte[ConstVaue.BufSize];
                int    curRecvedSize = 0;
                while (size.Number > 0)
                {
                    curRecvedSize += mStream.Read(messageBuffer, 0, size.Number);
                    if (curRecvedSize >= size.Number)
                    {
                        break;
                    }
                }
                Deserialize(ref mMessage, ref messageBuffer);
                Debug.Log("받은 메세지 = " + mMessage.Message);
                Thread.Sleep(100);
            }
            catch (Exception e)
            {
                Debug.Log(e.Message);
                mMessage.Message = "Exception";
                Debug.Log("Listen스레드 종료중..");
                mThreadListen.Abort();
                Debug.Log("Listen스레드 종료완료");
            }
        }
    }