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

Initialize() public method

This inializes the internal data structures of a NetworkConnection object, including channel buffers.

public Initialize ( string networkAddress, int networkHostId, int networkConnectionId, HostTopology hostTopology ) : void
networkAddress string The host or IP connected to.
networkHostId int The transport hostId for the connection.
networkConnectionId int The transport connectionId for the connection.
hostTopology HostTopology The topology to be used.
return void
        public virtual void Initialize(string networkAddress, int networkHostId, int networkConnectionId, HostTopology hostTopology)
        {
            this.m_Writer = new NetworkWriter();
            this.address = networkAddress;
            this.hostId = networkHostId;
            this.connectionId = networkConnectionId;
            int channelCount = hostTopology.DefaultConfig.ChannelCount;
            int packetSize = hostTopology.DefaultConfig.PacketSize;
            if ((hostTopology.DefaultConfig.UsePlatformSpecificProtocols && (Application.platform != RuntimePlatform.PS4)) && (Application.platform != RuntimePlatform.PSP2))
            {
                throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
            }
            this.m_Channels = new ChannelBuffer[channelCount];
            for (int i = 0; i < channelCount; i++)
            {
                ChannelQOS lqos = hostTopology.DefaultConfig.Channels[i];
                int bufferSize = packetSize;
                if ((lqos.QOS == QosType.ReliableFragmented) || (lqos.QOS == QosType.UnreliableFragmented))
                {
                    bufferSize = hostTopology.DefaultConfig.FragmentSize * 0x80;
                }
                this.m_Channels[i] = new ChannelBuffer(this, bufferSize, (byte) i, IsReliableQoS(lqos.QOS), IsSequencedQoS(lqos.QOS));
            }
        }

Usage Example

コード例 #1
0
 private void HandleConnect(int connectionId, byte error)
 {
     if (LogFilter.logDebug)
     {
         Debug.Log("NetworkServerSimple accepted client:" + connectionId);
     }
     if (error != 0)
     {
         this.OnConnectError(connectionId, error);
     }
     else
     {
         string    networkAddress;
         int       num;
         NetworkID networkID;
         NodeID    nodeID;
         byte      lastError;
         NetworkTransport.GetConnectionInfo(this.m_ServerHostId, connectionId, out networkAddress, out num, out networkID, out nodeID, out lastError);
         NetworkConnection networkConnection = (NetworkConnection)Activator.CreateInstance(this.m_NetworkConnectionClass);
         networkConnection.SetHandlers(this.m_MessageHandlers);
         networkConnection.Initialize(networkAddress, this.m_ServerHostId, connectionId, this.m_HostTopology);
         networkConnection.lastError = (NetworkError)lastError;
         while (this.m_Connections.Count <= connectionId)
         {
             this.m_Connections.Add(null);
         }
         this.m_Connections[connectionId] = networkConnection;
         this.OnConnected(networkConnection);
     }
 }
All Usage Examples Of UnityEngine.Networking.NetworkConnection::Initialize