AddChannel() public method

public AddChannel ( QosType value ) : byte
value QosType Add new channel to configuration.
return byte
Exemplo n.º 1
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");
    }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public virtual void Initialize()
        {
            if (m_Initialized)
            {
                return;
            }

            m_Initialized = true;
            NetworkTransport.Init();

            m_MsgBuffer = new byte[NetworkMessage.MaxMessageSize];
            m_MsgReader = new NetworkReader(m_MsgBuffer);

            if (m_HostTopology == null)
            {
                var config = new ConnectionConfig();
                config.AddChannel(QosType.ReliableSequenced);
                config.AddChannel(QosType.Unreliable);
                m_HostTopology = new HostTopology(config, 8);
            }

            if (LogFilter.logDebug)
            {
                Debug.Log("NetworkServerSimple initialize.");
            }
        }
Exemplo n.º 4
0
		// 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;
		}
Exemplo n.º 5
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);
    }
    // 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);
    }
	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");
	}
 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;
 }
 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);
 }
        public static void Setup(string port)
        {
            NetworkTransport.Init();

            ConnectionConfig config = new ConnectionConfig();
            channelSetupId = config.AddChannel(QosType.Reliable); // for lobby
            channelActionId = config.AddChannel(QosType.Reliable); // action in game
            channelConfirmationId = config.AddChannel(QosType.Reliable); // confirmation in game

            HostTopology topology = new HostTopology(config, maxConnection);
            hostId = NetworkTransport.AddHost(topology, Convert.ToInt32(port));

            self.enabled = true;
        }
Exemplo n.º 11
0
        void PrepareForConnect(bool usePlatformSpecificProtocols)
        {
            SetActive(true);
            RegisterSystemHandlers(false);

            if (m_HostTopology == null)
            {
                var config = new ConnectionConfig();
                config.AddChannel(QosType.ReliableSequenced);
                config.AddChannel(QosType.Unreliable);
                config.UsePlatformSpecificProtocols = usePlatformSpecificProtocols;
                m_HostTopology = new HostTopology(config, 8);
            }

            m_ClientId = NetworkTransport.AddHost(m_HostTopology, m_HostPort);
        }
Exemplo n.º 12
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!";
		}

	}
Exemplo n.º 13
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;
	}
    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;
            }
        }
    }
Exemplo n.º 15
0
	void Start()
	{
		DontDestroyOnLoad(this);
		
		//Build the global config
		GlobalConfig globalConfig = new GlobalConfig ();
		globalConfig.ReactorModel = ReactorModel.FixRateReactor;
		globalConfig.ThreadAwakeTimeout = 10;

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

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

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

		//Open a socket for the client
		clientSocketID = NetworkTransport.AddHost (hostTopology, 7777);

		//Make sure the client created the socket successfully
		if (clientSocketID < 0) 
		{
			Debug.Log ("Client socket creation failed!");
		} 
		else 
		{
			Debug.Log ("Client socket creation success");
		}
		//Create a byte to store a possible error
		byte error;
		//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
		clientServerConnectionID = 
			NetworkTransport.Connect(clientSocketID, Network.player.ipAddress.ToString(), 7777, 0, out error);
		//Display the error (if it did error out)
		if(error != (byte)NetworkError.Ok)
		{
			NetworkError networkError = (NetworkError)error;
			Debug.Log ("Error: " + networkError.ToString());
		}
	}
Exemplo n.º 16
0
    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);
    }
Exemplo n.º 17
0
 void Awake()
 {
     myClient = new NetworkClient ();
     ConnectionConfig config = new ConnectionConfig ();
     config.AddChannel (QosType.ReliableFragmented);
     myClient.Configure (config, 1);
     myClient.Connect (IP, 7777);
     myClient.RegisterHandler (MyMsgType.Info, OnInfoMessage);
 }
Exemplo n.º 18
0
 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);
 }
Exemplo n.º 19
0
 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);
 }
Exemplo n.º 20
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);
    }
Exemplo n.º 21
0
    // Use this for initialization
    void Start()
    {
        // Don't destroy the scene
        DontDestroyOnLoad(this);

        // Creates a new GlobalConfig that determines how it will react when receiving packets
        GlobalConfig globalConfig = new GlobalConfig();

        // Fixed rate makes it so it handles packets periodically (ie every 100 ms)
        globalConfig.ReactorModel = ReactorModel.FixRateReactor;

        // Sets so it deals with packets every 10 ms
        globalConfig.ThreadAwakeTimeout = 10;

        // Create a channel for packets to be sent across
        ConnectionConfig connectionConfig = new ConnectionConfig();

        // Create and set the reliable and unreliable channels
        reliableChannelID = connectionConfig.AddChannel(QosType.ReliableSequenced);
        unreliableChannelID = connectionConfig.AddChannel(QosType.UnreliableSequenced);

        // Create a host topology that determines the maximum number of clients the server can have
        HostTopology hostTopology = new HostTopology(connectionConfig, maxConnections);

        // Initialize the server
        NetworkTransport.Init(globalConfig);

        // Open the socket on your network
        serverSocketID = NetworkTransport.AddHost(hostTopology, 7777);

        // Check to see that the socket (and server) was successfully initialized
        if (serverSocketID < 0)
        {
            Debug.Log("Server socket creation failed!");
        }
        else
        {
            Debug.Log("Server socket creation success");
        }

        // Set server initialized to true
        serverInitialized = true;
    }
Exemplo n.º 22
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);
    }
Exemplo n.º 23
0
    // Use this for initialization
    void Start()
    {
        GlobalConfig globalConfig = new GlobalConfig(); //Stores information such as packet sizes
        globalConfig.ReactorModel = ReactorModel.FixRateReactor; //Determines how the network reacts to incoming packets
        globalConfig.ThreadAwakeTimeout = 10; //Amount of time in milliseconds between updateing packets

        ConnectionConfig connectionConfig = new ConnectionConfig(); //Stores all channels
        reliableChannelID = connectionConfig.AddChannel(QosType.ReliableSequenced); //TCP Channel
        unreliableChannelID = connectionConfig.AddChannel(QosType.UnreliableSequenced); //UDP Channel

        HostTopology hostTopology = new HostTopology(connectionConfig, maxConnections);

        NetworkTransport.Init(globalConfig);

        serverSocketID = NetworkTransport.AddHost(hostTopology, 7777);
        Debug.Log(serverSocketID);

        serverInitialized = true;
    }
Exemplo n.º 24
0
		// CONSTRUCTOR
		public Client(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<Player>();

			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);

			if(networkingInfo.isServer)
			{
				myClient = ClientScene.ConnectLocalServer();
				myClient.Configure(hostconfig);

				myClient.RegisterHandler(MsgType.Connect, OnConnected);
				myClient.RegisterHandler(MsgType.Disconnect, ConnectionFailed);
				registerAllCallbacks(myClient, cbClientHandler);
			}
			else
			{
				myClient = new NetworkClient();
				myClient.Configure(hostconfig);

				myClient.RegisterHandler(MsgType.Connect, OnConnected);
				myClient.RegisterHandler(MsgType.Error, ConnectionError);
				myClient.RegisterHandler(MsgType.Disconnect, ConnectionFailed);
				registerAllCallbacks(myClient, cbClientHandler);

				common.printConsole (tag, "Setup complete", true);

				myClient.Connect(networkingInfo.address, networkingInfo.port);
				common.printConsole (tag, "Connecting to " + networkingInfo.address + ":" + networkingInfo.port, true);
			}
		}
Exemplo n.º 25
0
    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);
    }
Exemplo n.º 26
0
 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);
 }
Exemplo n.º 27
0
 public virtual void Initialize()
 {
     if (!this.m_Initialized)
     {
         this.m_Initialized = true;
         NetworkTransport.Init();
         this.m_MsgBuffer = new byte[65535];
         this.m_MsgReader = new NetworkReader(this.m_MsgBuffer);
         if (this.m_HostTopology == null)
         {
             ConnectionConfig connectionConfig = new ConnectionConfig();
             connectionConfig.AddChannel(QosType.ReliableSequenced);
             connectionConfig.AddChannel(QosType.Unreliable);
             this.m_HostTopology = new HostTopology(connectionConfig, 8);
         }
         if (LogFilter.logDebug)
         {
             Debug.Log("NetworkServerSimple initialize.");
         }
     }
 }
Exemplo n.º 28
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 );
    }
Exemplo n.º 29
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.");
 }
Exemplo n.º 30
0
        public bool Initialize()
        {
            bool result;

            if (this.m_BroadcastData.Length >= 1024)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("NetworkDiscovery Initialize - data too large. max is " + 1024);
                }
                result = false;
            }
            else
            {
                if (!NetworkTransport.IsStarted)
                {
                    NetworkTransport.Init();
                }
                if (this.m_UseNetworkManager && NetworkManager.singleton != null)
                {
                    this.m_BroadcastData = string.Concat(new object[]
                    {
                        "NetworkManager:",
                        NetworkManager.singleton.networkAddress,
                        ":",
                        NetworkManager.singleton.networkPort
                    });
                    if (LogFilter.logInfo)
                    {
                        Debug.Log("NetworkDiscovery set broadcast 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 connectionConfig = new ConnectionConfig();
                connectionConfig.AddChannel(QosType.Unreliable);
                this.m_DefaultTopology = new HostTopology(connectionConfig, 1);
                if (this.m_IsServer)
                {
                    this.StartAsServer();
                }
                if (this.m_IsClient)
                {
                    this.StartAsClient();
                }
                result = true;
            }
            return(result);
        }
Exemplo n.º 31
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);
     }
 }
	public virtual void ConnectAsClient(int socketIdPar, string externalIp, int externalPort) {
		if (socketIdPar == 0) {
			localPort = getAvailablePort ();
			//Debug.Log ("Found free socket: " + localPort);
		} else {
			localPort = socketIdPar;
		}

		ConnectionConfig config = new ConnectionConfig();
		reliableChannelId  = config.AddChannel(QosType.Reliable);
		unreliableChannelId = config.AddChannel(QosType.Unreliable);

		topology = new HostTopology(config, 1);
		//TODO max connections on client?

		localSocketId = NetworkTransport.AddHost(topology, localPort);
		byte error;
		connectionId = NetworkTransport.Connect(localSocketId, externalIp, externalPort, 0, out error);
		if (((NetworkError)error) == NetworkError.Ok) {
			Debug.Log ("Connected as client to " + externalIp + ":" + externalPort);
		} else {
			Debug.Log ("Error connecting as client: " + ((NetworkError)error));
		}
	}
Exemplo n.º 33
0
        /// <summary>
        /// Initializes the NetworkDiscovery component.
        /// </summary>
        /// <returns>Return true if the network port was available.</returns>
        public bool Initialize()
        {
            if (m_BroadcastData.Length >= k_MaxBroadcastMsgSize)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("NetworkDiscovery Initialize - data too large. max is " + k_MaxBroadcastMsgSize);
                }
                return(false);
            }

            if (!NetworkManager.activeTransport.IsStarted)
            {
                NetworkManager.activeTransport.Init();
            }

            if (m_UseNetworkManager && NetworkManager.singleton != null)
            {
                m_BroadcastData = "NetworkManager:" + NetworkManager.singleton.networkAddress + ":" + NetworkManager.singleton.networkPort;
                if (LogFilter.logInfo)
                {
                    Debug.Log("NetworkDiscovery set broadcast data to:" + m_BroadcastData);
                }
            }

            m_MsgOutBuffer       = StringToBytes(m_BroadcastData);
            m_MsgInBuffer        = new byte[k_MaxBroadcastMsgSize];
            m_BroadcastsReceived = new Dictionary <string, NetworkBroadcastResult>();

            ConnectionConfig cc = new ConnectionConfig();

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

            if (m_IsServer)
            {
                StartAsServer();
            }

            if (m_IsClient)
            {
                StartAsClient();
            }

            return(true);
        }
 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);
 }
Exemplo n.º 35
0
	// Update is called once per frame
	void ConnectClient () {
		byte error;

		NetworkTransport.Init();
		ConnectionConfig config = new ConnectionConfig();
		myReliableChannelId = config.AddChannel(QosType.Reliable);
		HostTopology topology = new HostTopology(config, 1);
		hostId = NetworkTransport.AddHost(topology, Port);
		connectionId = NetworkTransport.Connect(hostId, ServerIP, Server.Port, 0, out error);

		if (error != (byte)NetworkError.Ok) {
			Debug.LogError("Client: error: " + (NetworkError)error); //not good
			return;
		}
		Debug.Log ("Client: connection succed");

		SendSocketMessage ();
	}
Exemplo n.º 36
0
        // Use this for initialization
        private void Start()
        {
            Screen.sleepTimeout = SleepTimeout.NeverSleep;

            var config = new ConnectionConfig();
            state = config.AddChannel(QosType.Unreliable);
            reliable = config.AddChannel(QosType.ReliableSequenced);
            var topology = new HostTopology(config, 1);

            host = NetworkTransport.AddHost(topology);

            ms = new MemoryStream(data);
            reader = new BinaryReader(ms);
            writer = new BinaryWriter(ms);

            NetworkTransport.StartBroadcastDiscovery(host, port, 1, 1, 0, new byte[1], 1, 2000, out error);
            PhoneServer.TestError(error);

            Input.gyro.enabled = true;
            Input.compass.enabled = true;
        }
Exemplo n.º 37
0
        public bool Initialize()
        {
            if (this.m_BroadcastData.Length >= 0x400)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("NetworkDiscovery Initialize - data too large. max is " + 0x400);
                }
                return(false);
            }
            if (!NetworkTransport.IsStarted)
            {
                NetworkTransport.Init();
            }
            if (this.m_UseNetworkManager && (NetworkManager.singleton != null))
            {
                object[] objArray1 = new object[] { "NetworkManager:", NetworkManager.singleton.networkAddress, ":", NetworkManager.singleton.networkPort };
                this.m_BroadcastData = string.Concat(objArray1);
                if (LogFilter.logInfo)
                {
                    Debug.Log("NetwrokDiscovery set broadbast data to:" + this.m_BroadcastData);
                }
            }
            this.m_MsgOutBuffer       = StringToBytes(this.m_BroadcastData);
            this.m_MsgInBuffer        = new byte[0x400];
            this.m_BroadcastsReceived = new Dictionary <string, NetworkBroadcastResult>();
            ConnectionConfig defaultConfig = new ConnectionConfig();

            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);
        }
Exemplo n.º 38
0
 public bool Initialize()
 {
     if (this.m_BroadcastData.Length >= 0x400)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("NetworkDiscovery Initialize - data too large. max is " + 0x400);
         }
         return false;
     }
     if (!NetworkTransport.IsStarted)
     {
         NetworkTransport.Init();
     }
     if (this.m_UseNetworkManager && (NetworkManager.singleton != null))
     {
         object[] objArray1 = new object[] { "NetworkManager:", NetworkManager.singleton.networkAddress, ":", NetworkManager.singleton.networkPort };
         this.m_BroadcastData = string.Concat(objArray1);
         if (LogFilter.logInfo)
         {
             Debug.Log("NetwrokDiscovery set broadbast data to:" + this.m_BroadcastData);
         }
     }
     this.m_MsgOutBuffer = StringToBytes(this.m_BroadcastData);
     this.m_MsgInBuffer = new byte[0x400];
     this.m_BroadcastsReceived = new Dictionary<string, NetworkBroadcastResult>();
     ConnectionConfig defaultConfig = new ConnectionConfig();
     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;
 }
Exemplo n.º 39
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);
        }
Exemplo n.º 40
0
        bool StartServer(MatchInfo info, ConnectionConfig config, int maxConnections)
        {
            InitializeSingleton();

            OnStartServer();

            if (m_RunInBackground)
            {
                Application.runInBackground = true;
            }

            NetworkCRC.scriptCRCCheck   = scriptCRCCheck;
            NetworkServer.useWebSockets = m_UseWebSockets;

            if (m_GlobalConfig != null)
            {
                NetworkTransport.Init(m_GlobalConfig);
            }

            // passing a config overrides setting the connectionConfig property
            if (m_CustomConfig && m_ConnectionConfig != null && config == null)
            {
                m_ConnectionConfig.Channels.Clear();
                foreach (var c in m_Channels)
                {
                    m_ConnectionConfig.AddChannel(c);
                }
                NetworkServer.Configure(m_ConnectionConfig, m_MaxConnections);
            }

            if (config != null)
            {
                NetworkServer.Configure(config, maxConnections);
            }

            if (info != null)
            {
                if (!NetworkServer.Listen(info, m_NetworkPort))
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("StartServer listen failed.");
                    }
                    return(false);
                }
            }
            else
            {
                if (m_ServerBindToIP && !string.IsNullOrEmpty(m_ServerBindAddress))
                {
                    if (!NetworkServer.Listen(m_ServerBindAddress, m_NetworkPort))
                    {
                        if (LogFilter.logError)
                        {
                            Debug.LogError("StartServer listen on " + m_ServerBindAddress + " failed.");
                        }
                        return(false);
                    }
                }
                else
                {
                    if (!NetworkServer.Listen(m_NetworkPort))
                    {
                        if (LogFilter.logError)
                        {
                            Debug.LogError("StartServer listen failed.");
                        }
                        return(false);
                    }
                }
            }

            // this must be after Listen(), since that registers the default message handlers
            RegisterServerMessages();

            if (LogFilter.logDebug)
            {
                Debug.Log("NetworkManager StartServer port:" + m_NetworkPort);
            }
            isNetworkActive = true;

            // Only change scene if the requested online scene is not blank, and is not already loaded
            string loadedSceneName = SceneManager.GetSceneAt(0).name;

            if (m_OnlineScene != "" && m_OnlineScene != loadedSceneName && m_OnlineScene != m_OfflineScene)
            {
                ServerChangeScene(m_OnlineScene);
            }
            else
            {
                NetworkServer.SpawnObjects();
            }
            return(true);
        }
Exemplo n.º 41
0
 private bool StartServer(MatchInfo info, ConnectionConfig config, int maxConnections)
 {
     OnStartServer();
     if (m_RunInBackground)
     {
         Application.runInBackground = true;
     }
     NetworkCRC.scriptCRCCheck = scriptCRCCheck;
     if (m_CustomConfig && m_ConnectionConfig != null && config == null)
     {
         m_ConnectionConfig.Channels.Clear();
         foreach (QosType channel in m_Channels)
         {
             m_ConnectionConfig.AddChannel(channel);
         }
         NetworkServer.Configure(m_ConnectionConfig, m_MaxConnections);
     }
     RegisterServerMessages();
     NetworkServer.sendPeerInfo  = m_SendPeerInfo;
     NetworkServer.useWebSockets = m_UseWebSockets;
     if (config != null)
     {
         NetworkServer.Configure(config, maxConnections);
     }
     if (info != null)
     {
         if (!NetworkServer.Listen(info, m_NetworkPort))
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("StartServer listen failed.");
             }
             return(false);
         }
     }
     else if (m_ServerBindToIP && !string.IsNullOrEmpty(m_ServerBindAddress))
     {
         if (!NetworkServer.Listen(m_ServerBindAddress, m_NetworkPort))
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("StartServer listen on " + m_ServerBindAddress + " failed.");
             }
             return(false);
         }
     }
     else if (!NetworkServer.Listen(m_NetworkPort))
     {
         if (LogFilter.logError)
         {
             Debug.LogError("StartServer listen failed.");
         }
         return(false);
     }
     if (LogFilter.logDebug)
     {
         Debug.Log("NetworkManager StartServer port:" + m_NetworkPort);
     }
     isNetworkActive = true;
     if (m_OnlineScene != string.Empty && m_OnlineScene != Application.loadedLevelName && m_OnlineScene != m_OfflineScene)
     {
         ServerChangeScene(m_OnlineScene);
     }
     else
     {
         NetworkServer.SpawnObjects();
     }
     return(true);
 }
Exemplo n.º 42
0
        private bool StartServer(MatchInfo info, ConnectionConfig config, int maxConnections)
        {
            InitializeSingleton();
            OnStartServer();
            if (m_RunInBackground)
            {
                Application.runInBackground = true;
            }
            NetworkCRC.scriptCRCCheck   = scriptCRCCheck;
            NetworkServer.useWebSockets = m_UseWebSockets;
            if (m_GlobalConfig != null)
            {
                NetworkTransport.Init(m_GlobalConfig);
            }
            if (m_CustomConfig && m_ConnectionConfig != null && config == null)
            {
                m_ConnectionConfig.Channels.Clear();
                for (int i = 0; i < m_Channels.Count; i++)
                {
                    m_ConnectionConfig.AddChannel(m_Channels[i]);
                }
                NetworkServer.Configure(m_ConnectionConfig, m_MaxConnections);
            }
            if (config != null)
            {
                NetworkServer.Configure(config, maxConnections);
            }
            if (info != null)
            {
                if (!NetworkServer.Listen(info, m_NetworkPort))
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("StartServer listen failed.");
                    }
                    return(false);
                }
            }
            else if (m_ServerBindToIP && !string.IsNullOrEmpty(m_ServerBindAddress))
            {
                if (!NetworkServer.Listen(m_ServerBindAddress, m_NetworkPort))
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("StartServer listen on " + m_ServerBindAddress + " failed.");
                    }
                    return(false);
                }
            }
            else if (!NetworkServer.Listen(m_NetworkPort))
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("StartServer listen failed.");
                }
                return(false);
            }
            RegisterServerMessages();
            if (LogFilter.logDebug)
            {
                Debug.Log("NetworkManager StartServer port:" + m_NetworkPort);
            }
            isNetworkActive = true;
            string name = SceneManager.GetSceneAt(0).name;

            if (!string.IsNullOrEmpty(m_OnlineScene) && m_OnlineScene != name && m_OnlineScene != m_OfflineScene)
            {
                ServerChangeScene(m_OnlineScene);
            }
            else
            {
                NetworkServer.SpawnObjects();
            }
            return(true);
        }