void Update() { // StartServer나 StartClient가 호출되어 초기화되기 전엔 아래의 코드를 실행하지 않음 if (_handler == null) { return; } // 핸들러가 모든 리소스를 정리하고 끝마칠 준비가 돼야 제거한다. // 서버나 클라이언트를 종료하고 난 후에도 처리해야할 이벤트가 있을 수 있기 때문이다. if (_handler.IsDead()) { _handler.OnRemoved(); _handler = null; IsOnline = false; IsServer = true; return; } // Notice we process all network events until we get a 'Nothing' response here. // Often people just process a single event per frame, and that results in very poor performance. var noEventsLeft = false; while (!noEventsLeft) { byte errorCode; int dataSize; int channelId; int connectionId; int hostId; var netEventType = NetworkTransport.Receive( out hostId, out connectionId, out channelId, _buffer, _buffer.Length, out dataSize, out errorCode); var error = (NetworkError)errorCode; if (error != NetworkError.Ok) { Debug.Log(string.Format("NetworkTransport error : {0}", error)); _handler.OnError(hostId, connectionId, channelId, error); return; } switch (netEventType) { case NetworkEventType.Nothing: noEventsLeft = true; break; case NetworkEventType.ConnectEvent: _handler.OnConnectEvent(hostId, connectionId, channelId); break; case NetworkEventType.DataEvent: _handler.OnDataEvent(hostId, connectionId, channelId, _buffer, dataSize); break; case NetworkEventType.DisconnectEvent: _handler.OnDisconnectEvent(hostId, connectionId, channelId); break; } } }