private void InitializeMasterServer() { // Initialize Master Server UnityEngine.Debug.Log("Attempting to initialize server..."); NetworkTransport.Init(); // Initialize NetworkTransport ConnectionConfig newConnectionConfig = new ConnectionConfig(); // Setup channels connectionData.channelReliable = newConnectionConfig.AddChannel(QosType.Reliable); connectionData.channelUnreliable = newConnectionConfig.AddChannel(QosType.Unreliable); connectionData.channelReliableFragmentedSequenced = newConnectionConfig.AddChannel(QosType.ReliableFragmentedSequenced); connectionData.channelReliableSequenced = newConnectionConfig.AddChannel(QosType.ReliableSequenced); HostTopology topology = new HostTopology(newConnectionConfig, connectionData.MAX_CONNECTION); // Setup topology connectionData.hostId = NetworkTransport.AddHost(topology, connectionData.port); //webHostId = NetworkTransport.AddWebsocketHost(topo, port, null); connectionData.isConnected = true; // TODO: could cause false start, check for true connection? UnityEngine.Debug.Log("Server initialized successfully!"); }
public static int AddHost(HostTopology topology, bool createServer) { if (!Enabled) { return(UnityEngine.Networking.NetworkTransport.AddHost(topology, 0, null)); } s_IsClient = !createServer; s_DefaultChannelId = topology.DefaultConfig.AddChannel(QosType.ReliableSequenced); SetChannelsFromTopology(topology); int ret = UnityEngine.Networking.NetworkTransport.AddHost(topology, 0, null); if (createServer) { s_RelayConnectionId = UnityEngine.Networking.NetworkTransport.Connect(ret, RelayAddress, RelayPort, 0, out byte b); } return(ret); }
public void StartServer() { NetworkTransport.Init(); ConnectionConfig cc = new ConnectionConfig(); reliableChannel = cc.AddChannel(QosType.Reliable); unreliableChannel = cc.AddChannel(QosType.Unreliable); HostTopology topo = new HostTopology(cc, MAX_CONNECTION); string PortField = GameObject.Find("PortInput").GetComponent <InputField>().text; if (PortField != "") { port = int.Parse(PortField); } hostId = NetworkTransport.AddHost(topo, port, null); webHostId = NetworkTransport.AddWebsocketHost(topo, port, null); Debug.Log("Starting server on port: " + port); isStarted = true; }
private void InitConnection() { NetworkTransport.Init(); ConnectionConfig cc = new ConnectionConfig(); _reliableChannel = cc.AddChannel(QosType.Reliable); HostTopology topo = new HostTopology(cc, MAX_USER); if (_isServer) { // SERVER ONLY _hostId = NetworkTransport.AddHost(topo, PORT, null); _webHostId = NetworkTransport.AddWebsocketHost(topo, WEB_PORT, null); Debug.Log(string.Format("Opening connection on port {0} and webport {1}", PORT, WEB_PORT)); _isStarted = true; } else { // Client ONLY _connectionData.hostId = NetworkTransport.AddHost(topo, 0); #if !UNITY_WEBGL // standalone client _connectionData.connectionId = NetworkTransport.Connect(_connectionData.hostId, _serwerIp, PORT, 0, out _error); Debug.Log(string.Format("Connecting from standalone")); #else // web client m_ConnectionData.connectionId = NetworkTransport.Connect(m_ConnectionData.hostId, serwerIp, WEB_PORT, 0, out error); Debug.Log(string.Format("Connecting from web")); #endif Debug.Log(string.Format("Attempting to connect on {0}....", _serwerIp)); _isStarted = true; } }
public void Connect() { byte error; config = new ConnectionConfig(); channelId = config.AddChannel(QosType.ReliableSequenced); hostTopology = new HostTopology(config, 1); hostId = NetworkTransport.AddHost(hostTopology, port); connectionId = NetworkTransport.Connect(hostId, host, port, 0, out error); NetworkError networkError = (NetworkError)error; if (networkError != NetworkError.Ok) { Debug.LogError($"Unable to connect to {host}:{port}, Error: {networkError}"); } else { Debug.Log(string.Format("Connected to {0}:{1} with hostId: {2}, connectionId: {3}, channelId: {4},", host, port, hostId, connectionId, channelId)); } }
public void Start(object objectContainingRpcs, Func <object, UnityEngine.GameObject> createGameObjectFromState) { Assert.IsTrue(!IsStarted); ObjectContainingRpcs = objectContainingRpcs; this.createGameObjectFromState = createGameObjectFromState; ShouldApplyStateSnapshots = true; var maxConnectionCount = 1; // The client only connects to the server. var connectionConfig = NetLib.CreateConnectionConfig( out reliableSequencedChannelId, out reliableChannelId, out unreliableStateUpdateChannelId, out unreliableFragmentedChannelId, out unreliableChannelId ); var hostTopology = new HostTopology( connectionConfig, maxConnectionCount ); Start(null, hostTopology); }
private void ConnectToServer() { NetUsers = new Dictionary <int, NetUser>(); PlayerInstances = new Dictionary <int, NetPlayer>(); GlobalConfig globalconfig = new GlobalConfig() { ThreadPoolSize = _threadPoolSize }; NetworkTransport.Init(globalconfig); ConnectionConfig connectionConfig = new ConnectionConfig() { SendDelay = 0, MinUpdateTimeout = 1 }; ReliableChannel = connectionConfig.AddChannel(QosType.Reliable); UnreliableChannel = connectionConfig.AddChannel(QosType.Unreliable); HostTopology hostTopology = new HostTopology(connectionConfig, 16); _socketId = NetworkTransport.AddHost(hostTopology, 0); byte error; _serverConnectionId = NetworkTransport.Connect(_socketId, _serverAdress, _serverPort, 0, out error); if (error != 0) { Debug.LogError($"@Client -> @ConnectToServer : [{error}]"); } else { StartCoroutine(Receiver()); Debug.Log($"@Client -> @ConnectToServer : [{_socketId}]"); } }
public void StartServer() { if (isServerStarted) { Debug.Log("Server already started!!!!"); return; } if (isClientConnected) { Debug.Log("Already joined as client!!!"); } ConnectionConfig connectionConfig = new ConnectionConfig(); reliableChannel = connectionConfig.AddChannel(QosType.Reliable); unreliableChannel = connectionConfig.AddChannel(QosType.Unreliable); HostTopology networkTopology = new HostTopology(connectionConfig, MAX_CONNECTIONS); hostId = NetworkTransport.AddHost(networkTopology, port, null); // connectionId = NetworkTransport.AddWebsocketHost(networkTopology, port, null); GenerateServerBoxes(); isServerStarted = true; Debug.Log("Hosting Server Locally"); debugText.text += "Hosting Server Locally | HostConnectionId: " + connectionId + " | "; ServerClient host = new ServerClient(); host.playerName = "Host"; host.playerPrefab = playerPrefab; host.isLocalPlayer = true; host.connectionId = connectionId; hostConnectionId = connectionId; clientsList.Add(host); WorldCenter.AddComponent <WorldAnchor>(); }
// Use this for initialization private void Start() { 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); filter = PlayerPrefs.GetString("filter", ""); multiSend = PlayerPrefs.GetInt("multiSend", 0) == 1; port = PlayerPrefs.GetInt("port", port); number = PlayerPrefs.GetInt("number", number); frequency = PlayerPrefs.GetInt("frequency", frequency); UpdateConnected(); }
public void Connect() { if (isServerStarted) { Debug.Log("Cannot be server and client at the same time"); return; } if (isClientConnected) { Debug.Log("Already joined as client!!!"); } playerName = "player_a"; hostIp = serverIp.text; if (serverIp.text == "") { hostIp = "192.168.100.4"; } ConnectionConfig connectionConfig = new ConnectionConfig(); reliableChannel = connectionConfig.AddChannel(QosType.Reliable); unreliableChannel = connectionConfig.AddChannel(QosType.Unreliable); HostTopology networkTopology = new HostTopology(connectionConfig, MAX_CONNECTIONS); hostId = NetworkTransport.AddHost(networkTopology, 0); Debug.Log("connecting to: " + hostIp); debugText.text += "connecting to: " + hostIp + " | "; connectionId = NetworkTransport.Connect(hostId, hostIp, port, 0, out error); Debug.Log((NetworkError)error); connectionTime = Time.time; isClientConnected = true; }
public void Init() { db = new MongoData(); db.Init(); NetworkTransport.Init(); ConnectionConfig cc = new ConnectionConfig(); reliableChannel = cc.AddChannel(QosType.Reliable); HostTopology topo = new HostTopology(cc, MAX_USER); //Server Only hostId = NetworkTransport.AddHost(topo, PORT, null); webhostId = NetworkTransport.AddWebsocketHost(topo, WEB_PORT, null); Debug.Log(string.Format("Oppening connection on port {0} and webport {1}", PORT, WEB_PORT)); isStarted = true; // // Test // db.InsertAccount("testUsername","testPassword","testEmail"); }
public static int AddWebsocketHost(HostTopology topology, int port, string ip, bool createServer) { if (!Enabled) { return(NetworkTransport.AddWebsocketHost(topology, port, ip)); } isClient = !createServer; defaultChannelId = topology.DefaultConfig.AddChannel(QosType.ReliableSequenced); SetChannelsFromTopology(topology); int ret = NetworkTransport.AddWebsocketHost(topology, port, ip); if (createServer) { relayConnectionId = NetworkTransport.Connect(ret, RelayAddress, RelayPort, 0, out byte b); } return(ret); }
public void SetupA() { game.SetPlayer1(); if (game.localNet) { myIP = "127.0.0.1"; remoteIP = "127.0.0.1"; } else { myIP = "149.153.106.154"; remoteIP = "149.153.106.155"; } myPort = 8001; remotePort = 8000; HostTopology topology = new HostTopology(config, maxConnections); hostId = NetworkTransport.AddHost(topology, myPort); }
public void Init() { // lower poll rate to save CPU Application.targetFrameRate = 10; NetworkTransport.Init(); ConnectionConfig connectionConfig = new ConnectionConfig(); reliableChannel = connectionConfig.AddChannel(QosType.Reliable); HostTopology topo = new HostTopology(connectionConfig, MAX_USER); hostId = NetworkTransport.AddHost(topo, PORT, null); webHostId = NetworkTransport.AddWebsocketHost(topo, WEB_PORT); Debug.Log(string.Format("Opening connection on port {0} and webport {1}", PORT, WEB_PORT)); isStarted = true; db = new Datastore(); db.Init(); }
void Start() { //Seems to like to auto launch full screen, don't do that... Screen.fullScreen = !Screen.fullScreen; dicPlayers = new Dictionary <int, string>(); dicNetObjects = new Dictionary <int, NetworkedObject>(); dicOwner = new Dictionary <int, List <int> >(); //initializing the Transport Layer GlobalConfig gConfig = new GlobalConfig(); NetworkTransport.Init(gConfig); ConnectionConfig config = new ConnectionConfig(); myReliableChannelId = config.AddChannel(QosType.Reliable); HostTopology topology = new HostTopology(config, 100); hostId = NetworkTransport.AddHost(topology, 8888); Debug.Log("Ready for connections!"); }
public void Connect() { ConnectionConfig config = new ConnectionConfig(); reliableChannelId = config.AddChannel(QosType.ReliableSequenced); HostTopology topology = new HostTopology(config, maxConnections); hostId = NetworkTransport.AddHost(topology, socketPort); connectionId = NetworkTransport.Connect(hostId, RecvIP, serverSocketPort, 0, out error); NetworkError networkError = (NetworkError)error; if (networkError != NetworkError.Ok) { Debug.LogError(string.Format("Unable to connect to {0}:{1}, Error: {2}", hostId, serverSocketPort, networkError)); } else { Debug.Log(string.Format("Connected to {0}:{1} with hostId: {2}, connectionId: {3}, channelId: {4},", hostId, serverSocketPort, hostId, connectionId, reliableChannelId)); } connected = true; }
// Use this for initialization void Start() { // Build global config GlobalConfig gc = new GlobalConfig(); gc.ReactorModel = ReactorModel.FixRateReactor; gc.ThreadAwakeTimeout = 10; // Build channel config ConnectionConfig cc = new ConnectionConfig(); mChannelReliable = cc.AddChannel(QosType.ReliableSequenced); mChannelUnreliable = cc.AddChannel(QosType.UnreliableSequenced); // Create host topology from config HostTopology ht = new HostTopology(cc, mMaxConnections); // We have all of our other stuff figured out, so init NetworkTransport.Init(gc); // Open sockets for server and client mClientSocket = NetworkTransport.AddHost(ht); // Check to make sure our socket formations were successful if (mClientSocket < 0) { UI_Manager.AddTextItem("Client socket creation failed!"); } else { UI_Manager.AddTextItem("Client socket creation successful!"); } // Connect to server byte error; mClientConnection = NetworkTransport.Connect(mClientSocket, "127.0.0.1", 8888, 0, out error); LogNetworkError(error); }
public override bool Start( out string error ) { ConnectionConfig config = InitializeNetwork( out error ); if( config == null ) { return false; } // clients only ever have one connection, to the server HostTopology topology = new HostTopology( config, 1 ); // 0 in AddHost means we choose a random free port for the client int hostId = NetworkTransport.AddHost( topology, 0 ); if( hostId != 0 ) { error = $"Got unexpected hostId:{hostId}"; return false; } _status = Status.Disconnected; return Reconnect( out error ); }
void SetupNetwork() { string ipaddrs = "*"; NetworkTransport.Init(); // get the last (or only) IP address IPAddress[] addrs = Dns.GetHostAddresses(Dns.GetHostName()); foreach (IPAddress myip in addrs) { if (myip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { Debug.Log(myip.ToString()); ipaddrs = myip.ToString(); } } ConnectionConfig config = new ConnectionConfig(); int channelId = config.AddChannel(QosType.Reliable); HostTopology topology = new HostTopology(config, 10); hostId = NetworkTransport.AddHost(topology, 8761, ipaddrs); // need to close port when done. Where? How? Tune in next episode to find out.. }
public static int AddHostWithSimulator(HostTopology topology, int minTimeout, int maxTimeout, bool createServer) { if (!Enabled) { return(NetworkTransport.AddHostWithSimulator(topology, minTimeout, maxTimeout)); } isClient = !createServer; defaultChannelId = topology.DefaultConfig.AddChannel(QosType.ReliableSequenced); SetChannelsFromTopology(topology); int ret = NetworkTransport.AddHostWithSimulator(topology, minTimeout, maxTimeout); if (createServer) { relayConnectionId = NetworkTransport.Connect(ret, RelayAddress, RelayPort, 0, out byte b); } return(ret); }
public void Connect() { string pName = GameObject.Find("NameInput").GetComponent <InputField>().text; if (pName == "") { Debug.Log("Wpisz imie"); return; } string IpField = GameObject.Find("IpInput").GetComponent <InputField>().text; if (IpField != "") { ip = GameObject.Find("IpInput").GetComponent <InputField>().text; } string PortField = GameObject.Find("PortInput").GetComponent <InputField>().text; if (PortField != "") { port = int.Parse(PortField); } playerName = pName; NetworkTransport.Init(); ConnectionConfig cc = new ConnectionConfig(); reliableChannel = cc.AddChannel(QosType.Reliable); unreliableChannel = cc.AddChannel(QosType.Unreliable); HostTopology topo = new HostTopology(cc, MAX_CONNECTION); hostId = NetworkTransport.AddHost(topo, 0); connectionId = NetworkTransport.Connect(hostId, ip, port, 0, out error); Debug.Log(error.ToString()); connectionTime = Time.time; isConnected = true; }
// ---------------------------- // Setup Network // ---------------------------- void server_setup() { /// Global Config defines global paramters for network library. GlobalConfig global_configuration = new GlobalConfig(); global_configuration.ReactorModel = ReactorModel.SelectReactor; global_configuration.ThreadAwakeTimeout = 10; /// Add a channel to send and recieve /// Build channel configuration ConnectionConfig connection_configuration = new ConnectionConfig(); server_real_reliable_channel = connection_configuration.AddChannel(QosType.Reliable); server_reliable_channel = connection_configuration.AddChannel(QosType.UnreliableSequenced); /// Create Network Topology for host configuration /// This topology defines: /// (1) how many connection with default config will be supported/ /// (2) what will be special connections (connections with config different from default). HostTopology host_topology = new HostTopology(connection_configuration, max_connections); /// Initializes the NetworkTransport. /// Should be called before any other operations on the NetworkTransport are done. NetworkTransport.Init(); // Open sockets for server and client server_socket_ID = NetworkTransport.AddHost(host_topology, server_port); if (server_socket_ID < 0) { Debug.Log("Server socket creation failed!"); } else { Debug.Log("Server socket creation successful!"); } }
private void InitializeClient(string serverIP, HostTopology topology) { if (m_Settings.m_SimulateNetworking) { m_HostID = NetworkTransport.AddHostWithSimulator(topology, m_Settings.m_MinLatency, m_Settings.m_MaxLatency, 0); } else { m_HostID = NetworkTransport.AddHost(topology, 0); } byte error; if (m_Settings.m_SimulateNetworking) { int min = m_Settings.m_MinLatency; int avg = (m_Settings.m_MinLatency + m_Settings.m_MaxLatency) / 2; ConnectionSimulatorConfig conf = new ConnectionSimulatorConfig(min, avg, min, avg, m_Settings.m_PacketLoss); ConnectionID = NetworkTransport.ConnectWithSimulator(m_HostID, serverIP, m_Settings.m_Port, 0, out error, conf); } else { ConnectionID = NetworkTransport.Connect(m_HostID, serverIP, m_Settings.m_Port, 0, out error); } DebugLog(string.Format("Connecting to {0}...", serverIP)); if ((NetworkError)error != NetworkError.Ok) { DebugLog("Connection failed: " + (NetworkError)error); return; } RegisterHandlers(); }
/// <summary> /// Tries to estabilish a connection to server, using provided IP address and port number. /// Default IP is 127.0.0.1 and default port is 8888. /// In case of connection failure, up to 3 retries are executed. /// Sets the "Initialized" flag on success. /// </summary> /// <param name="ipAddress">IP address entered by user</param> /// <param name="portNumber">Port number entered by user</param> /// <returns></returns> public bool ConnectToServer(string ipAddress, int portNumber) { ConnectionConfig connectionConfig = new ConnectionConfig(); reliableChannelId = connectionConfig.AddChannel(QosType.Reliable); unreliableChannelId = connectionConfig.AddChannel(QosType.UnreliableSequenced); maxConnections = 3; HostTopology hostTopology = new HostTopology(connectionConfig, maxConnections); socketPort = portNumber - 1; int retryCount = 0; while (retryCount < 3) { //Up to 3 retries/3 connections socketId = NetworkTransport.AddHost(hostTopology, socketPort); InfoMenu.Instance.WriteLine("Started NetworkTransport host on port " + socketPort + ", socketID is " + socketId); Debug.Log("Started NetworkTransport host on port " + socketPort + ", socketID is " + socketId); byte error; connectionId = NetworkTransport.Connect(socketId, ipAddress, portNumber, 0, out error); Debug.Log("New connection id: " + connectionId); if ((NetworkError)error != NetworkError.Ok) //If connection failed { Debug.Log("ooops - " + (NetworkError)error + ", try no. " + retryCount); Debug.Log("Odpauzuj jesli wyskoczy blad :P Albo odznacz pause on error"); retryCount++; socketPort--; } else // If connected successfully { Initialized = true; return(true); //InitializePlayer(); //break; } } return(false); }
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); }
// Use this for initialization void Start() { Application.runInBackground = true; NetworkTransport.Init(); if (_apachePortNumber != "80" || _apachePortNumber != "") { _LoginURL = "http://localhost:" + _apachePortNumber + "/teamnewport/LoginManager.php"; _CreateAccountURL = "http://localhost:" + _apachePortNumber + "/teamnewport/CreateAccount.php"; } ConnectionConfig config = new ConnectionConfig(); TCP_ChannelID = config.AddChannel(QosType.Reliable); UDP_ChannelIDSeq = config.AddChannel(QosType.UnreliableSequenced); UDP_ChannelIDFrag = config.AddChannel(QosType.UnreliableFragmented); UDP_ChannelID = config.AddChannel(QosType.Unreliable); _maxConnections = _maxGameInstances * 4; HostTopology hostTopology = new HostTopology(config, _maxConnections); _socketID = NetworkTransport.AddHost(hostTopology, _socketPort); }
public void StartHosting(ConnectionConfig cc, int maxPlayersPerRoom, out int socketId, out int webSocketId, int socketPort) { NetworkTransport.Init(NetManager.instance.networkConfiguration); HostTopology topology = new HostTopology(cc, maxPlayersPerRoom); socketId = NetworkTransport.AddHost(topology, socketPort, null); webSocketId = NetworkTransport.AddWebsocketHost(topology, socketPort, null); if (socketId == -1) { Destroy(this); } else { isHosting = true; Debug.Log("Started hosting on port " + socketPort); if (OnStartHosting != null) { OnStartHosting(); } } }
// Use this for initialization void Start() { _chatText.text = ""; _sendTextInput.text = ""; Application.runInBackground = true; RegisterHandlers(); var config = new ConnectionConfig(); config.AddChannel(QosType.Reliable); config.AddChannel(QosType.Unreliable); var ht = new HostTopology(config, _maxConnections); if (!NetworkServer.Configure(ht) || !NetworkServer.Listen(_port)) { Debug.LogError("No server created"); return; } else { Debug.Log("Chat Server Started"); } }
public override SocketTasks StartServer() { var topology = new HostTopology(GetConfig(), MaxConnections); if (SupportWebsocket) { if (!UseMLAPIRelay) { int websocketHostId = UnityEngine.Networking.NetworkTransport.AddWebsocketHost(topology, ServerWebsocketListenPort); } else { if (NetworkLog.CurrentLogLevel <= LogLevel.Error) { NetworkLog.LogError("Cannot create websocket host when using MLAPI relay"); } } } int normalHostId = RelayTransport.AddHost(topology, ServerListenPort, true); return(SocketTask.Done.AsTasks()); }
public override void StartServer() { UpdateRelay(); HostTopology topology = new HostTopology(GetConfig(), MaxConnections); if (SupportWebsocket) { if (!UseMLAPIRelay) { int websocketHostId = NetworkTransport.AddWebsocketHost(topology, ServerWebsocketListenPort); } else { if (LogHelper.CurrentLogLevel <= LogLevel.Error) { LogHelper.LogError("Cannot create websocket host when using MLAPI relay"); } } } int normalHostId = RelayTransport.AddHost(topology, ServerListenPort, true); }