UnityEngine.Networking.NetworkConnection.TransportRecieve C# (CSharp) Method

TransportRecieve() public method

This virtual function allows custom network connection classes to process data from the network before it is passed to the application.

public TransportRecieve ( byte bytes, int numBytes, int channelId ) : void
bytes byte The data recieved.
numBytes int The size of the data recieved.
channelId int The channel that the data was received on.
return void
        public virtual void TransportRecieve(byte[] bytes, int numBytes, int channelId)
        {
            this.HandleBytes(bytes, numBytes, channelId);
        }

Usage Example

コード例 #1
0
        internal virtual void Update()
        {
            if (m_ClientId == -1)
            {
                return;
            }
            switch (m_AsyncConnect)
            {
            case ConnectState.None:
            case ConnectState.Resolving:
            case ConnectState.Disconnected:
                return;

            case ConnectState.Failed:
                GenerateConnectError(11);
                m_AsyncConnect = ConnectState.Disconnected;
                return;

            case ConnectState.Resolved:
                m_AsyncConnect = ConnectState.Connecting;
                ContinueConnect();
                return;
            }
            if (m_Connection != null && (int)Time.time != m_StatResetTime)
            {
                m_Connection.ResetStats();
                m_StatResetTime = (int)Time.time;
            }
            NetworkEventType networkEventType;

            do
            {
                int num = 0;
                networkEventType = NetworkTransport.ReceiveFromHost(m_ClientId, out int _, out int channelId, m_MsgBuffer, (ushort)m_MsgBuffer.Length, out int receivedSize, out byte error);
                if (networkEventType != NetworkEventType.Nothing && LogFilter.logDev)
                {
                    Debug.Log("Client event: host=" + m_ClientId + " event=" + networkEventType + " error=" + error);
                }
                switch (networkEventType)
                {
                case NetworkEventType.ConnectEvent:
                    if (LogFilter.logDebug)
                    {
                        Debug.Log("Client connected");
                    }
                    if (error != 0)
                    {
                        GenerateConnectError(error);
                        return;
                    }
                    m_AsyncConnect = ConnectState.Connected;
                    m_Connection.InvokeHandlerNoData(32);
                    break;

                case NetworkEventType.DataEvent:
                    if (error != 0)
                    {
                        GenerateDataError(error);
                        return;
                    }
                    m_MsgReader.SeekZero();
                    m_Connection.TransportRecieve(m_MsgBuffer, receivedSize, channelId);
                    break;

                case NetworkEventType.DisconnectEvent:
                    if (LogFilter.logDebug)
                    {
                        Debug.Log("Client disconnected");
                    }
                    m_AsyncConnect = ConnectState.Disconnected;
                    if (error != 0)
                    {
                        GenerateDisconnectError(error);
                    }
                    ClientScene.HandleClientDisconnect(m_Connection);
                    m_Connection.InvokeHandlerNoData(33);
                    break;

                default:
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Unknown network message type received: " + networkEventType);
                    }
                    break;

                case NetworkEventType.Nothing:
                    break;
                }
                if (num + 1 >= 500)
                {
                    if (LogFilter.logDebug)
                    {
                        Debug.Log("MaxEventsPerFrame hit (" + 500 + ")");
                    }
                    break;
                }
            }while (m_ClientId != -1 && networkEventType != NetworkEventType.Nothing);
            if (m_Connection != null && m_AsyncConnect == ConnectState.Connected)
            {
                m_Connection.FlushChannels();
            }
        }
All Usage Examples Of UnityEngine.Networking.NetworkConnection::TransportRecieve