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
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 2
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((int)NetworkError.DNSFailure);
                m_AsyncConnect = ConnectState.Disconnected;
                return;

            case ConnectState.Resolved:
                m_AsyncConnect = ConnectState.Connecting;
                ContinueConnect();
                return;

            case ConnectState.Connecting:
            case ConnectState.Connected:
            {
                break;
            }
            }

            if (m_Connection != null)
            {
                if ((int)Time.time != m_StatResetTime)
                {
                    m_Connection.ResetStats();
                    m_StatResetTime = (int)Time.time;
                }
            }

            NetworkEventType networkEvent;

            do
            {
                int  connectionId;
                int  channelId;
                int  receivedSize;
                byte error;
                int  numEvents = 0;

                networkEvent = NetworkTransport.ReceiveFromHost(m_ClientId, out connectionId, out channelId, m_MsgBuffer, (ushort)m_MsgBuffer.Length, out receivedSize, out error);

                if (networkEvent != NetworkEventType.Nothing)
                {
                    if (LogFilter.logDev)
                    {
                        Debug.Log("Client event: host=" + m_ClientId + " event=" + networkEvent + " error=" + error);
                    }
                }

                switch (networkEvent)
                {
                case NetworkEventType.ConnectEvent:

                    if (LogFilter.logDebug)
                    {
                        Debug.Log("Client connected");
                    }

                    if (error != 0)
                    {
                        GenerateConnectError(error);
                        return;
                    }

                    m_AsyncConnect = ConnectState.Connected;
                    m_Connection.InvokeHandlerNoData(MsgType.Connect);
                    break;

                case NetworkEventType.DataEvent:
                    if (error != 0)
                    {
                        GenerateDataError(error);
                        return;
                    }

#if UNITY_EDITOR
                    UnityEditor.NetworkDetailStats.IncrementStat(
                        UnityEditor.NetworkDetailStats.NetworkDirection.Incoming,
                        MsgType.LLAPIMsg, "msg", 1);
#endif

                    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)
                    {
                        if ((NetworkError)error != NetworkError.Timeout)
                        {
                            GenerateDisconnectError(error);
                        }
                    }
                    ClientScene.HandleClientDisconnect(m_Connection);
                    if (m_Connection != null)
                    {
                        m_Connection.InvokeHandlerNoData(MsgType.Disconnect);
                    }
                    break;

                case NetworkEventType.Nothing:
                    break;

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

                if (++numEvents >= k_MaxEventsPerFrame)
                {
                    if (LogFilter.logDebug)
                    {
                        Debug.Log("MaxEventsPerFrame hit (" + k_MaxEventsPerFrame + ")");
                    }
                    break;
                }
                if (m_ClientId == -1)
                {
                    break;
                }
            }while (networkEvent != NetworkEventType.Nothing);

            if (m_Connection != null && m_AsyncConnect == ConnectState.Connected)
            {
                m_Connection.FlushChannels();
            }
        }
Ejemplo n.º 3
0
 public virtual void OnData(NetworkConnection conn, int receivedSize, int channelId)
 {
     conn.TransportRecieve(m_MsgBuffer, receivedSize, channelId);
 }
Ejemplo n.º 4
0
 private void OnData(NetworkConnection conn, int receivedSize, int channelId)
 {
     NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Incoming, 0x1d, "msg", 1);
     conn.TransportRecieve(this.m_SimpleServerSimple.messageBuffer, receivedSize, channelId);
 }