示例#1
0
        private void OnReceiveData(IAsyncResult result)
        {
            try
            {
                int packetLength = myStream.EndRead(result);
                receivedBytes = new byte[packetLength];
                Buffer.BlockCopy(asyncBuffer, 0, receivedBytes, 0, packetLength);

                if (packetLength == 0)
                {
                    Debug.LogWarning("서버와의 접속이 끊겼습니다.");
                    UnityThread.ExecuteInUpdate(() =>
                    {
                        Application.Quit();
                    });
                    return;
                }
                UnityThread.ExecuteInUpdate(() =>
                {
                    NetworkHandleData.HandleData(receivedBytes);
                });
                myStream.BeginRead(asyncBuffer, 0, NetworkSettings.CLIENT_BUFFERSIZE * 2, OnReceiveData, null);
            }
            catch (Exception)
            {
                Debug.LogWarning("서버와의 접속이 끊겼습니다.");
                UnityThread.ExecuteInUpdate(() =>
                {
                    Application.Quit();
                });
                return;
            }
        }
示例#2
0
 void Start()
 {
     networkSettings   = new NetworkSettings("null", "127.0.0.1");
     network           = GetComponent <Network>();
     networkHandleData = new NetworkHandleData();
     networkHandleData.InitializePackets();
     network.ConnectIP();
 }