コード例 #1
0
	public bool Initialize()
	{
		if (m_BroadcastData.Length >= kMaxBroadcastMsgSize)
		{
			Debug.LogError("NetworkDiscovery Initialize - data too large. max is " + kMaxBroadcastMsgSize);
			return false;
		}

		if (!NetworkTransport.IsStarted)
		{
			NetworkTransport.Init();
		}

		if (NetworkManager.singleton != null)
		{
			m_BroadcastData = "NetworkManager:"+NetworkManager.singleton.networkAddress + ":" + NetworkManager.singleton.networkPort;
		}

		msgOutBuffer = StringToBytes(m_BroadcastData);
		msgInBuffer = new byte[kMaxBroadcastMsgSize];

		ConnectionConfig cc = new ConnectionConfig();
		cc.AddChannel(QosType.Unreliable);
		defaultTopology = new HostTopology(cc, 1);

		if (m_IsServer)
			StartAsServer();

		if (m_IsClient)
			StartAsClient();

		return true;
	}
コード例 #2
0
    void Start()
    {
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.ReactorModel = ReactorModel.FixRateReactor;
        globalConfig.ThreadAwakeTimeout = 10;

        ConnectionConfig connectionConfig = new ConnectionConfig();
        reliableChannelID = connectionConfig.AddChannel(QosType.ReliableSequenced);
        unreliableChannelID = connectionConfig.AddChannel(QosType.UnreliableSequenced);

        HostTopology hostTopology = new HostTopology(connectionConfig, maxConnections);

        NetworkTransport.Init(globalConfig);

        serverSocketID = NetworkTransport.AddHost(hostTopology, 7777);

        if(serverSocketID < 0)
        {
            Debug.Log("Server socket creation failed!");
        }
        else
        {
            Debug.Log("Server socket creation success.");
        }

        serverInitialized = true;

        DontDestroyOnLoad(this);
    }
コード例 #3
0
    void Awake()
    {
        try
        {
            NetworkTransport.Init();

            serverConfig = new ConnectionConfig();
            serverChannelId = serverConfig.AddChannel(QosType.StateUpdate);  // QosType.UnreliableFragmented
            serverConfig.MaxSentMessageQueueSize = 2048;  // 128 by default

            serverTopology = new HostTopology(serverConfig, maxConnections);
            serverHostId = NetworkTransport.AddHost(serverTopology, listenOnPort);

            liRelTime = 0;
            fCurrentTime = Time.time;

            System.DateTime dtNow = System.DateTime.UtcNow;
            Debug.Log("Kinect data server started at " + dtNow.ToString() + " - " + dtNow.Ticks);

            if(statusText)
            {
                statusText.text = "Server running: 0 connection(s)";
            }
        }
        catch (System.Exception ex)
        {
            Debug.LogError(ex.Message + "\n" + ex.StackTrace);

            if(statusText)
            {
                statusText.text = ex.Message;
            }
        }
    }
コード例 #4
0
    void Start()
    {
        DontDestroyOnLoad(this);

        //Build the global config
        GlobalConfig clientGlobalConfig = new GlobalConfig();
        clientGlobalConfig.ReactorModel = ReactorModel.FixRateReactor;
        clientGlobalConfig.ThreadAwakeTimeout = 10;

        //Build the channel config
        ConnectionConfig clientConnectionConfig = new ConnectionConfig();
        reliableChannelID = clientConnectionConfig.AddChannel(QosType.ReliableSequenced);
        unreliableChannelID = clientConnectionConfig.AddChannel(QosType.UnreliableSequenced);

        //Create the host topology
        HostTopology hostTopology = new HostTopology(clientConnectionConfig, maxConnections);

        //Initialize the network transport
        NetworkTransport.Init(clientGlobalConfig);

        //Open a socket for the client

        //Make sure the client created the socket successfully

        //Create a byte to store a possible error
        byte possibleError;

        //Connect to the server using
        //int NetworkTransport.Connect(int socketConnectingFrom, string ipAddress, int port, 0, out byte possibleError)
        //Store the ID of the connection in clientServerConnectionID
        NetworkTransport.Connect(clientSocketID, " ", 7777, 0, out possibleError);

        //Display the error (if it did error out)
        Debug.Log("Connection Failed");
    }
コード例 #5
0
 public HostTopologyInternal(HostTopology topology)
 {
   this.InitWrapper(new ConnectionConfigInternal(topology.DefaultConfig), topology.MaxDefaultConnections);
   for (int i = 1; i <= topology.SpecialConnectionConfigsCount; ++i)
     this.AddSpecialConnectionConfig(new ConnectionConfigInternal(topology.GetSpecialConnectionConfig(i)));
   this.InitOtherParameters(topology);
 }
コード例 #6
0
        /// <summary>
        /// Attempt to connect to a given address and port.
        /// </summary>
        /// <param name="address">The IP to try and connect to</param>
        /// <param name="port">The port to try and connect to</param>
        /// <returns>True if connection was successful and false if you are already connected or connection failed.</returns>
        public bool Connect(string address, int port)
        {
            if (m_isConnected)
            {
                Debug.LogError(LLAPS.FormatError(typeof(ClientConnection), "The client is already connected, please call Disconnect before calling Connect again."));
                return false;
            }

            NetworkTransport.Init();

            var configBehaviour = this.GetComponent<Common.ConnectionConfig>();
            var configuration = configBehaviour.GetConnectionConfiguration();

            m_qosChannels.Clear();
            foreach (var channel in this.Channels)
            {
                m_qosChannels[channel] = configuration.AddChannel(channel);
            }

            var topology = new HostTopology(configuration, c_maxClientConnections);
            m_genericHostId = NetworkTransport.AddHost(topology, 0);

            byte error;
            m_connectionId = NetworkTransport.Connect(m_genericHostId, address, port, 0, out error);
            if (error != 0 || m_connectionId == 0)
            {
                Debug.LogError(LLAPS.FormatError(typeof(ClientConnection), string.Format("Failed to connect to {0}:{1}. ErrorCode: {2}", address, port, error)));
                m_connectionId = LLAPS.c_invalidId;
                return false;
            }

            m_isConnected = true;
            return true;
        }
コード例 #7
0
ファイル: RelayClient.cs プロジェクト: vildninja/unet
        public void Connect(string ip)
        {
            NetworkTransport.Init();

            // Config must be identical with the server
            var config = new ConnectionConfig();
            config.PacketSize = 1000;
            infoChannel = config.AddChannel(QosType.ReliableSequenced);
            gameChannel = config.AddChannel(QosType.ReliableSequenced);

            // Setup the host socket (yes also for clients)
            // Using port 0 to let the system assign a random available port
            var topology = new HostTopology(config, 200);
            server.host = NetworkTransport.AddHost(topology, 0);

            byte error;
            server.conn = NetworkTransport.Connect(server.host, ip, port, 0, out error);

            Log.TestError(error, "Failed to connect to the server!");

            // Setup the data buffer:
            data = new byte[config.PacketSize];
            // And setup a reader and writer for easy data manipulation
            stream = new MemoryStream(data);
            reader = new BinaryReader(stream);
            writer = new BinaryWriter(stream);
        }
コード例 #8
0
    // Use this for initialization
    void Start()
    {
        GlobalConfig globalConfig = new GlobalConfig();
        // Set the Global Config to receive data in fixed 10ms intervals.
        globalConfig.ReactorModel = ReactorModel.FixRateReactor;
        globalConfig.ThreadAwakeTimeout = INTERVAL_TIME;

        ConnectionConfig connectionConfig = new ConnectionConfig();
        // Add data channels to the network
        reliableChannelID = connectionConfig.AddChannel(QosType.ReliableSequenced);
        unreliableChannelID = connectionConfig.AddChannel(QosType.UnreliableSequenced);
        // Combine channels with the maximum number of connections
        HostTopology hostTopology = new HostTopology(connectionConfig, maxConnections);
        // Initialize the Network
        NetworkTransport.Init(globalConfig);
        // Open the network socket
        serverSocketID = NetworkTransport.AddHost(hostTopology, DEFAULT_PORT);
        if (serverSocketID < 0)
            Debug.Log("Server socket creation failed");
        else
            Debug.Log("Server socket creation successful");
        // Note that the server is running
        serverInitialized = true;
        DontDestroyOnLoad(this);
    }
コード例 #9
0
ファイル: Server.cs プロジェクト: Johannesolof/DoDGame
		// CONSTRUCTOR
		public Server(NetworkingInfo netinfo)
		{
			networkingInfo = netinfo;
			if(networkingInfo.port == -1) networkingInfo.port = NetworkingInfo.defaultPort;
			if(networkingInfo.address == "") networkingInfo.address = NetworkingInfo.defaultAddress;
			// TODO: Add some kind of DNS pre check for IP?

			connectedPlayers = new List<ServerPlayer>();
			whiteList = new Dictionary<string, DateTime>();
			pendingConnections = new Queue<NetworkConnection>();

			config = new ConnectionConfig();
			Channels.priority = config.AddChannel(QosType.AllCostDelivery);
			Channels.reliable = config.AddChannel(QosType.ReliableSequenced);
			Channels.unreliable = config.AddChannel(QosType.UnreliableSequenced);
			Channels.fragmented = config.AddChannel(QosType.ReliableFragmented);
			Channels.update = config.AddChannel(QosType.StateUpdate);
			hostconfig = new HostTopology(config, maxConcurrentConnectedUsers);

			NetworkServer.Configure(hostconfig);
			NetworkServer.Listen(networkingInfo.port);
			NetworkServer.RegisterHandler(MsgType.Connect, OnClientConnected);
			common.printConsole (tag, "Setup complete", true);
			networkingInfo.address = NetworkingCommon.localServer;
		}
コード例 #10
0
	public void CreateSocket() {
	
		if (_hostID > -1)
			return;

		if (inputIP.text.Length == 0 || inputPort.text.Length == 0) {

			errorField.text = "IP Address or Port Error";
			return;

		}

		_port = int.Parse (inputPort.text);
		_address = inputIP.text;

		//http://docs.unity3d.com/Manual/UNetUsingTransport.html
		NetworkTransport.Init ();
		ConnectionConfig config = new ConnectionConfig ();
		
		_unreliableID = config.AddChannel (QosType.Unreliable);	// http://blogs.unity3d.com/2014/06/11/all-about-the-unity-networking-transport-layer/
		
		int maxConnections = 10;
		
		HostTopology topology = new HostTopology (config, maxConnections);
		
		_hostID = NetworkTransport.AddHost (topology, _port);
		Debug.Log ("Socket Open.  _hostID: " + _hostID);

		if (_hostID > -1) {
			errorField.text = "Socket Connected!";
		}

	}
コード例 #11
0
ファイル: Test.cs プロジェクト: hpoggie/Backstab-Networking
 void StartServer()
 {
     ConnectionConfig config = new ConnectionConfig();
     config.AddChannel(QosType.Unreliable);
     HostTopology topology = new HostTopology(config, 10);
     localSocketId = NetworkTransport.AddHost(topology, 0);
     byte err;
     NetworkTransport.StartBroadcastDiscovery(localSocketId, 8888, 1000, 1, 1, StringToBytes("Hello World"), 1024, 1000, out err);
 }
コード例 #12
0
ファイル: Test.cs プロジェクト: hpoggie/Backstab-Networking
 void StartClient()
 {
     ConnectionConfig config = new ConnectionConfig();
     config.AddChannel(QosType.Unreliable);
     HostTopology topology = new HostTopology(config, 10);
     localSocketId = NetworkTransport.AddHost(topology, 8888);
     byte err;
     NetworkTransport.SetBroadcastCredentials(localSocketId, 1000, 1, 1, out err);
 }
コード例 #13
0
    private void init()
    {
        NetworkTransport.Init();

        ConnectionConfig config = new ConnectionConfig();
        mReliableChannelId = config.AddChannel(QosType.Reliable);

        HostTopology topology = new HostTopology(config, MAX_CONNECTIONS);
        mHostId = NetworkTransport.AddHost(topology, PORT);
    }
コード例 #14
0
    // Use this for initialization
    void Start()
    {
        NetworkTransport.Init ();

        ConnectionConfig config = new ConnectionConfig();
        reiliableChannelId  = config.AddChannel(QosType.Reliable);
        HostTopology topology = new HostTopology(config, 5);

        hostId = NetworkTransport.AddWebsocketHost(topology, 8081, null);
    }
コード例 #15
0
	public virtual void SetupAsServer(int socketId, int maxConnections) {
		ConnectionConfig config = new ConnectionConfig();
		reliableChannelId  = config.AddChannel(QosType.Reliable);
		unreliableChannelId = config.AddChannel(QosType.Unreliable);

		topology = new HostTopology(config, maxConnections);

		localSocketId = NetworkTransport.AddHost(topology, socketId);
		Debug.Log ("Set up server at port: " + socketId + " With a maximum of " + maxConnections + " Connections");
	}
コード例 #16
0
    /// <summary>
    /// Initializes a new instance of the <see cref="NetClient"/> class.
    /// </summary>
    /// <param name="socket">Valid socket id for the NetClient. Given by NetManager.</param>
    public NetClient()
    {
        HostTopology ht = new HostTopology( NetManager.mConnectionConfig , 1 ); // Clients only need 1 connection
        int csocket = NetworkTransport.AddHost ( ht  );

        if(!NetUtils.IsSocketValid (csocket)){
            Debug.Log ("NetManager::CreateClient() returned an invalid socket ( " + csocket + " )" );
        }

        mSocket = csocket;
    }
コード例 #17
0
ファイル: Networking.cs プロジェクト: CryptArc/ScoreBall
 public void Host()
 {
     //initialize and configure stuff
     ConnectionConfig config = new ConnectionConfig();
     reliableChannelID = config.AddChannel(QosType.Reliable);
     HostTopology topology = new HostTopology(config, maxConnections);
     //open up a socket
     socketID = NetworkTransport.AddHost(topology, port);
     outputText.text = "opened socket: " + socketID;
     Debug.Log(outputText.text);
 }
コード例 #18
0
ファイル: Server.cs プロジェクト: Final-Parsec/TheVenomEvent
    void Start()
    {
        NetworkTransport.Init();
        ConnectionConfig config = new ConnectionConfig();
        reliableChannelId = config.AddChannel(QosType.Reliable);

        HostTopology topology = new HostTopology(config, maxConnections);

        socketId = NetworkTransport.AddHost(topology, socketPort);
        Debug.Log("Socket Open. SocketId is: " + socketId + " ChannelID is: " + reliableChannelId);
    }
コード例 #19
0
    // Use this for initialization
    void Start()
    {
        UnityEngine.Networking.NetworkTransport.Init ();

        ConnectionConfig connConf = new ConnectionConfig ();

        HostTopology hostTopology = new HostTopology (connConf, 1024);

        int hostId = NetworkTransport.AddHost (hostTopology, Port, Interface);
        print ("Now listening on " + Interface + ":" + Port);
    }
コード例 #20
0
 public LLApiClient (string endPoint, int port, GameClient gameClient)
 {
     Config = new ConnectionConfig();
     int ReliableChannelId = Config.AddChannel(QosType.Reliable);
     int NonReliableChannelId = Config.AddChannel(QosType.Unreliable);
     Topology = new HostTopology(Config, 10);
     EndPoint = endPoint;
     Port = port;
     GameClient = gameClient;
     isConnected = false;
 }
コード例 #21
0
 public HostTopologyInternal(HostTopology topology)
 {
     ConnectionConfigInternal config = new ConnectionConfigInternal(topology.DefaultConfig);
     this.InitWrapper(config, topology.MaxDefaultConnections);
     for (int i = 1; i <= topology.SpecialConnectionConfigsCount; i++)
     {
         ConnectionConfigInternal internal3 = new ConnectionConfigInternal(topology.GetSpecialConnectionConfig(i));
         this.AddSpecialConnectionConfig(internal3);
     }
     this.InitOtherParameters(topology);
 }
コード例 #22
0
 public static int AddHostWithSimulator(HostTopology topology, int minTimeout, int maxTimeout, [DefaultValue("0")] int port, [DefaultValue("null")] string ip)
 {
     if (topology == null)
     {
         throw new NullReferenceException("topology is not defined");
     }
     if (ip == null)
     {
         return AddHostWrapperWithoutIp(new HostTopologyInternal(topology), port, minTimeout, maxTimeout);
     }
     return AddHostWrapper(new HostTopologyInternal(topology), ip, port, minTimeout, maxTimeout);
 }
コード例 #23
0
 public LLApiServer(GameServer gameServer, int port, ushort maxConnections, ushort maxMessages)
 {
     GameServer = gameServer;
     Port = port;
     MaxConnections = maxConnections;
     MaxMessages = maxMessages;
     isConnected = false;
     Config = new ConnectionConfig();
     int ReliableChannelId = Config.AddChannel(QosType.Reliable);
     int NonReliableChannelId = Config.AddChannel(QosType.Unreliable);
     Topology = new HostTopology(Config, MaxConnections);
 }
コード例 #24
0
ファイル: WebClient.cs プロジェクト: vildninja/voxel
        public WebClient(HostTopology topology)
        {
            buffer = new byte[WebManager.PACKET_SIZE];

            ms = new MemoryStream(buffer);
            reader = new BinaryReader(ms);
            writer = new BinaryWriter(ms);
            
            channel = 0;
            movement = 1;
            host = NetworkTransport.AddHost(topology, 0);
        }
コード例 #25
0
 /// <summary>
 /// <para>Creates a host based on Networking.HostTopology.</para>
 /// </summary>
 /// <param name="topology">The Networking.HostTopology associated with the host.</param>
 /// <param name="port">Port to bind to (when 0 is selected, the OS will choose a port at random).</param>
 /// <param name="ip">IP address to bind to.</param>
 /// <returns>
 /// <para>Returns the ID of the host that was created.</para>
 /// </returns>
 public static int AddHost(HostTopology topology, [DefaultValue("0")] int port, [DefaultValue("null")] string ip)
 {
     if (topology == null)
     {
         throw new NullReferenceException("topology is not defined");
     }
     CheckTopology(topology);
     if (ip == null)
     {
         return AddHostWrapperWithoutIp(new HostTopologyInternal(topology), port, 0, 0);
     }
     return AddHostWrapper(new HostTopologyInternal(topology), ip, port, 0, 0);
 }
コード例 #26
0
    public MutliplayerManager()
    {
        // Packet config
        GlobalConfig gConfig = new GlobalConfig();
        gConfig.MaxPacketSize = 500;

        NetworkTransport.Init( gConfig );

        // Connection config
        ConnectionConfig config = new ConnectionConfig();
        int mainChannel = config.AddChannel(QosType.Unreliable);

        topology = new HostTopology( config, 10 );
    }
コード例 #27
0
    /// <summary>
    /// Initializes a new instance of the <see cref="NetServer"/> class.
    /// </summary>
    /// <param name="maxConnections">Max connections.</param>
    /// <param name="port">Port.</param>
    public NetServer( int maxConnections , int port )
    {
        if(!NetManager.mIsInitialized){
            Debug.Log ("NetServer( ... ) - NetManager was not initialized. Did you forget to call NetManager.Init()?");
            return;
        }

        HostTopology ht = new HostTopology( NetManager.mConnectionConfig , maxConnections );
        mSocket = NetworkTransport.AddHost ( ht , port  );

        if(!NetUtils.IsSocketValid (mSocket)){
            Debug.Log ("NetServer::NetServer( " + maxConnections + " , " + port.ToString () + " ) returned an invalid socket ( " + mSocket.ToString() + " )" );
        }

        mIsRunning = true;
    }
コード例 #28
0
 private void InitUnetBroadcastDiscovery()
 {
     byte num;
     if (!NetworkTransport.IsStarted)
     {
         NetworkTransport.Init();
     }
     ConnectionConfig defaultConfig = new ConnectionConfig();
     defaultConfig.AddChannel(QosType.Unreliable);
     HostTopology topology = new HostTopology(defaultConfig, 1);
     this.hostId = NetworkTransport.AddHost(topology, 0xbaa1);
     if (this.hostId == -1)
     {
         Debug.LogError("Network Discovery addHost failed!");
     }
     NetworkTransport.SetBroadcastCredentials(this.hostId, 0x3e8, 1, 1, out num);
 }
コード例 #29
0
ファイル: TransportNET.cs プロジェクト: coringuyen/Networking
    void Start ()
    {
        NetworkTransport.Init();

        ConnectionConfig config = new ConnectionConfig();

        int myReiliableChannelId = config.AddChannel(QosType.Reliable);
        int myUnreliableChannelId = config.AddChannel(QosType.Unreliable);
        HostTopology topology = new HostTopology(config, 10);

        int hostId = NetworkTransport.AddHost(topology, 8888);

        int bufferLength = buffer.Length;
        int connectionId = NetworkTransport.Connect(hostId, "192.16.7.21", 8888, 0, out error);
        NetworkTransport.Disconnect(hostId, connectionId, out error);
        NetworkTransport.Send(hostId, connectionId, myReiliableChannelId, buffer, bufferLength, out error);
    }
コード例 #30
0
    protected override void ConfigureHosts(ConnectionConfig config)
    {
        HostTopology topology = new HostTopology(config, 5);
        if (hostID != -1)
            return;
        #if UNITY_EDITOR
        // Listen on port 25000
        if(simulatedNetworking)
            hostID = NetworkTransport.AddHost(topology, 25000);
        else
            hostID = NetworkTransport.AddHostWithSimulator(topology, 200, 400, 25000);
        #else
        hostID = NetworkTransport.AddHost(topology, 25000);
        #endif

        Debug.Log(Format.localIPAddress());
    }
コード例 #31
0
        /// <summary>
        ///   <para>Initializes the NetworkDiscovery component.</para>
        /// </summary>
        /// <returns>
        ///   <para>Return true if the network port was available.</para>
        /// </returns>
        public bool Initialize()
        {
            if (this.m_BroadcastData.Length >= 1024)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError((object)("NetworkDiscovery Initialize - data too large. max is " + (object)1024));
                }
                return(false);
            }
            if (!NetworkTransport.IsStarted)
            {
                NetworkTransport.Init();
            }
            if (this.m_UseNetworkManager && (UnityEngine.Object)NetworkManager.singleton != (UnityEngine.Object)null)
            {
                this.m_BroadcastData = "NetworkManager:" + NetworkManager.singleton.networkAddress + ":" + (object)NetworkManager.singleton.networkPort;
                if (LogFilter.logInfo)
                {
                    Debug.Log((object)("NetwrokDiscovery set broadbast data to:" + this.m_BroadcastData));
                }
            }
            this.m_MsgOutBuffer       = NetworkDiscovery.StringToBytes(this.m_BroadcastData);
            this.m_MsgInBuffer        = new byte[1024];
            this.m_BroadcastsReceived = new Dictionary <string, NetworkBroadcastResult>();
            ConnectionConfig defaultConfig = new ConnectionConfig();
            int num = (int)defaultConfig.AddChannel(QosType.Unreliable);

            this.m_DefaultTopology = new HostTopology(defaultConfig, 1);
            if (this.m_IsServer)
            {
                this.StartAsServer();
            }
            if (this.m_IsClient)
            {
                this.StartAsClient();
            }
            return(true);
        }
コード例 #32
0
        public bool Initialize()
        {
            if (m_BroadcastData.Length >= 1024)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("NetworkDiscovery Initialize - data too large. max is " + 1024);
                }
                return(false);
            }
            if (!NetworkTransport.IsStarted)
            {
                NetworkTransport.Init();
            }
            if (m_UseNetworkManager && NetworkManager.singleton != null)
            {
                m_BroadcastData = "NetworkManager:" + NetworkManager.singleton.networkAddress + ":" + NetworkManager.singleton.networkPort;
                if (LogFilter.logInfo)
                {
                    Debug.Log("NetwrokDiscovery set broadbast data to:" + m_BroadcastData);
                }
            }
            m_MsgOutBuffer       = StringToBytes(m_BroadcastData);
            m_MsgInBuffer        = new byte[1024];
            m_BroadcastsReceived = new Dictionary <string, NetworkBroadcastResult>();
            ConnectionConfig connectionConfig = new ConnectionConfig();

            connectionConfig.AddChannel(QosType.Unreliable);
            m_DefaultTopology = new HostTopology(connectionConfig, 1);
            if (m_IsServer)
            {
                StartAsServer();
            }
            if (m_IsClient)
            {
                StartAsClient();
            }
            return(true);
        }
コード例 #33
0
 /// <summary>
 ///   <para>Initialization function that is invoked when the server starts listening. This can be overridden to perform custom initialization such as setting the NetworkConnectionClass.</para>
 /// </summary>
 public virtual void Initialize()
 {
     if (this.m_Initialized)
     {
         return;
     }
     this.m_Initialized = true;
     NetworkTransport.Init();
     this.m_MsgBuffer = new byte[(int)ushort.MaxValue];
     this.m_MsgReader = new NetworkReader(this.m_MsgBuffer);
     if (this.m_HostTopology == null)
     {
         ConnectionConfig defaultConfig = new ConnectionConfig();
         int num1 = (int)defaultConfig.AddChannel(QosType.Reliable);
         int num2 = (int)defaultConfig.AddChannel(QosType.Unreliable);
         this.m_HostTopology = new HostTopology(defaultConfig, 8);
     }
     if (!LogFilter.logDebug)
     {
         return;
     }
     Debug.Log((object)"NetworkServerSimple initialize.");
 }
コード例 #34
0
 public bool Listen(int serverListenPort, HostTopology topology)
 {
     m_HostTopology = topology;
     Initialize();
     m_ListenPort = serverListenPort;
     if (m_UseWebSockets)
     {
         m_ServerHostId = NetworkTransport.AddWebsocketHost(m_HostTopology, serverListenPort);
     }
     else
     {
         m_ServerHostId = NetworkTransport.AddHost(m_HostTopology, serverListenPort);
     }
     if (m_ServerHostId == -1)
     {
         return(false);
     }
     if (LogFilter.logDebug)
     {
         Debug.Log("NetworkServerSimple listen " + m_ListenPort);
     }
     return(true);
 }
コード例 #35
0
 private void PrepareForConnect(bool usePlatformSpecificProtocols)
 {
     NetworkClient.SetActive(true);
     this.RegisterSystemHandlers(false);
     if (this.m_HostTopology == null)
     {
         ConnectionConfig connectionConfig = new ConnectionConfig();
         connectionConfig.AddChannel(QosType.ReliableSequenced);
         connectionConfig.AddChannel(QosType.Unreliable);
         connectionConfig.UsePlatformSpecificProtocols = usePlatformSpecificProtocols;
         this.m_HostTopology = new HostTopology(connectionConfig, 8);
     }
     if (this.m_UseSimulator)
     {
         int num = this.m_SimulatedLatency / 3 - 1;
         if (num < 1)
         {
             num = 1;
         }
         int num2 = this.m_SimulatedLatency * 3;
         if (LogFilter.logDebug)
         {
             Debug.Log(string.Concat(new object[]
             {
                 "AddHost Using Simulator ",
                 num,
                 "/",
                 num2
             }));
         }
         this.m_ClientId = NetworkTransport.AddHostWithSimulator(this.m_HostTopology, num, num2, this.m_HostPort);
     }
     else
     {
         this.m_ClientId = NetworkTransport.AddHost(this.m_HostTopology, this.m_HostPort);
     }
 }
コード例 #36
0
        static int s_MaxPacketStats = 255;//the same as maximum message types
#endif

        public virtual void Initialize(string networkAddress, int networkHostId, int networkConnectionId, HostTopology hostTopology)
        {
            m_Writer     = new NetworkWriter();
            address      = networkAddress;
            hostId       = networkHostId;
            connectionId = networkConnectionId;

            int numChannels = hostTopology.DefaultConfig.ChannelCount;
            int packetSize  = hostTopology.DefaultConfig.PacketSize;

            if ((hostTopology.DefaultConfig.UsePlatformSpecificProtocols) && (UnityEngine.Application.platform != RuntimePlatform.PS4) && (UnityEngine.Application.platform != RuntimePlatform.PSP2))
            {
                throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
            }

            m_Channels = new ChannelBuffer[numChannels];
            for (int i = 0; i < numChannels; i++)
            {
                var qos = hostTopology.DefaultConfig.Channels[i];
                int actualPacketSize = packetSize;
                if (qos.QOS == QosType.ReliableFragmented || qos.QOS == QosType.UnreliableFragmented)
                {
                    actualPacketSize = hostTopology.DefaultConfig.FragmentSize * 128;
                }
                m_Channels[i] = new ChannelBuffer(this, actualPacketSize, (byte)i, IsReliableQoS(qos.QOS), IsSequencedQoS(qos.QOS));
            }
        }
コード例 #37
0
 public static int AddHost(HostTopology top, int port, string ip)
 {
     return(0);
 }
コード例 #38
0
 public static int AddHost(HostTopology top)
 {
     return(0);
 }
コード例 #39
0
 public static int AddHostWithSimulator(HostTopology top, int mintimeout, int maxTimeout, int port, string ip)
 {
     return(0);
 }
コード例 #40
0
 public static int AddWebsocketHost(HostTopology top, int port)
 {
     return(0);
 }
コード例 #41
0
        /// <summary>
        ///   <para>This inializes the internal data structures of a NetworkConnection object, including channel buffers.</para>
        /// </summary>
        /// <param name="address">The host or IP connected to.</param>
        /// <param name="hostId">The transport hostId for the connection.</param>
        /// <param name="connectionId">The transport connectionId for the connection.</param>
        /// <param name="hostTopology">The topology to be used.</param>
        /// <param name="networkAddress"></param>
        /// <param name="networkHostId"></param>
        /// <param name="networkConnectionId"></param>
        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   = (int)hostTopology.DefaultConfig.PacketSize;

            if (hostTopology.DefaultConfig.UsePlatformSpecificProtocols && Application.platform != RuntimePlatform.PS4)
            {
                throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
            }
            this.m_Channels = new ChannelBuffer[channelCount];
            for (int index = 0; index < channelCount; ++index)
            {
                ChannelQOS channel    = hostTopology.DefaultConfig.Channels[index];
                int        bufferSize = packetSize;
                if (channel.QOS == QosType.ReliableFragmented || channel.QOS == QosType.UnreliableFragmented)
                {
                    bufferSize = (int)hostTopology.DefaultConfig.FragmentSize * 128;
                }
                this.m_Channels[index] = new ChannelBuffer(this, bufferSize, (byte)index, NetworkConnection.IsReliableQoS(channel.QOS));
            }
        }
コード例 #42
0
        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;

            this.m_Channels = new ChannelBuffer[channelCount];
            for (int i = 0; i < channelCount; i++)
            {
                ChannelQOS lqos = hostTopology.DefaultConfig.Channels[i];
                this.m_Channels[i] = new ChannelBuffer(this, packetSize, (byte)i, IsReliableQoS(lqos.QOS));
            }
        }
コード例 #43
0
 static public int AddHost(HostTopology topology, int port, string ip)
 {
     return(AddHostWithSimulator(topology, 0, 0, port, ip));
 }
コード例 #44
0
 private static void SetChannelsFromTopology(HostTopology topology) => channels = topology.DefaultConfig.Channels;
コード例 #45
0
        public static int AddHost(HostTopology topology, int port)
        {
            string ip = null;

            return(AddHost(topology, port, ip));
        }
コード例 #46
0
        public bool Configure(ConnectionConfig config, int maxConnections)
        {
            HostTopology topology = new HostTopology(config, maxConnections);

            return(Configure(topology));
        }
コード例 #47
0
 public int AddWebsocketHost(HostTopology topology, int port, string ip)
 {
     return(NetworkTransport.AddWebsocketHost(topology, port, ip));
 }
コード例 #48
0
        public virtual void Initialize(string networkAddress, int networkHostId, int networkConnectionId, HostTopology hostTopology)
        {
            address      = networkAddress;
            hostId       = networkHostId;
            connectionId = networkConnectionId;

            if ((hostTopology.DefaultConfig.UsePlatformSpecificProtocols) && (Application.platform != RuntimePlatform.PS4) && (Application.platform != RuntimePlatform.PSP2))
            {
                throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
            }
        }
コード例 #49
0
        public static int AddHost(HostTopology topology, int port)
        {
            string ip = (string)null;

            return(NetworkTransport.AddHost(topology, port, ip));
        }
コード例 #50
0
        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   = (int)hostTopology.DefaultConfig.PacketSize;

            this.m_Channels = new ChannelBuffer[channelCount];
            for (int i = 0; i < channelCount; i++)
            {
                ChannelQOS channelQOS = hostTopology.DefaultConfig.Channels[i];
                int        bufferSize = packetSize;
                if (channelQOS.QOS == QosType.ReliableFragmented || channelQOS.QOS == QosType.UnreliableFragmented)
                {
                    bufferSize = (int)(hostTopology.DefaultConfig.FragmentSize * 128);
                }
                this.m_Channels[i] = new ChannelBuffer(this, bufferSize, (byte)i, NetworkConnection.IsReliableQoS(channelQOS.QOS));
            }
        }
コード例 #51
0
        public static int AddHostWithSimulator(HostTopology topology, int minTimeout, int maxTimeout, int port)
        {
            string ip = (string)null;

            return(NetworkTransport.AddHostWithSimulator(topology, minTimeout, maxTimeout, port, ip));
        }
コード例 #52
0
        /// <summary>
        /// <para>This inializes the internal data structures of a NetworkConnection object, including channel buffers.</para>
        /// </summary>
        /// <param name="hostTopology">The topology to be used.</param>
        /// <param name="networkAddress">The host or IP connected to.</param>
        /// <param name="networkHostId">The transport hostId for the connection.</param>
        /// <param name="networkConnectionId">The transport connectionId for the connection.</param>
        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));
            }
        }
コード例 #53
0
 public static int AddWebsocketHost(HostTopology topology, int port)
 {
     return(NetworkTransport.AddWebsocketHost(topology, port, null));
 }
コード例 #54
0
 public int AddHostWithSimulator(HostTopology topology, int minTimeout, int maxTimeout, int port)
 {
     return(NetworkTransport.AddHostWithSimulator(topology, minTimeout, maxTimeout, port));
 }
コード例 #55
0
 public bool Configure(HostTopology topology)
 {
     m_HostTopology = topology;
     return(true);
 }
コード例 #56
0
 static public int AddHost(HostTopology topology)
 {
     return(AddHost(topology, 0, null));
 }
コード例 #57
0
 private void InitOtherParameters(HostTopology topology)
 {
     this.InitReceivedPoolSize(topology.ReceivedMessagePoolSize);
     this.InitSentMessagePoolSize(topology.SentMessagePoolSize);
     this.InitMessagePoolSizeGrowthFactor(topology.MessagePoolSizeGrowthFactor);
 }
コード例 #58
0
 static public int AddWebsocketHost(HostTopology topology, int port)
 {
     return(AddWebsocketHost(topology, port, null));
 }
コード例 #59
0
        public static int AddHostWithSimulator(HostTopology topology, int minTimeout, int maxTimeout, int port)
        {
            string ip = null;

            return(AddHostWithSimulator(topology, minTimeout, maxTimeout, port, ip));
        }
コード例 #60
0
 static public int AddHostWithSimulator(HostTopology topology, int minTimeout, int maxTimeout)
 {
     return(AddHostWithSimulator(topology, minTimeout, maxTimeout, 0, null));
 }