void ConnectWithRelay(MatchInfo info) { m_AsyncConnect = ConnectState.Connecting; Update(); byte error; m_ClientConnectionId = NetworkManager.activeTransport.ConnectToNetworkPeer( m_ClientId, info.address, info.port, 0, 0, info.networkId, Utility.GetSourceID(), info.nodeId, out error); m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass); m_Connection.SetHandlers(m_MessageHandlers); m_Connection.Initialize(info.address, m_ClientId, m_ClientConnectionId, m_HostTopology); if (error != 0) { Debug.LogError("ConnectToNetworkPeer Error: " + error); } }
internal void ContinueConnect() { byte error; // regular non-relay connect if (m_UseSimulator) { int simLatency = m_SimulatedLatency / 3; if (simLatency < 1) { simLatency = 1; } if (LogFilter.logDebug) { Debug.Log("Connect Using Simulator " + (m_SimulatedLatency / 3) + "/" + m_SimulatedLatency); } var simConfig = new ConnectionSimulatorConfig( simLatency, m_SimulatedLatency, simLatency, m_SimulatedLatency, m_PacketLoss); m_ClientConnectionId = NetworkManager.activeTransport.ConnectWithSimulator(m_ClientId, m_ServerIp, m_ServerPort, 0, out error, simConfig); } else { m_ClientConnectionId = NetworkManager.activeTransport.Connect(m_ClientId, m_ServerIp, m_ServerPort, 0, out error); } m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass); m_Connection.SetHandlers(m_MessageHandlers); m_Connection.Initialize(m_ServerIp, m_ClientId, m_ClientConnectionId, m_HostTopology); }
void HandleConnect(int connectionId, byte error) { if (LogFilter.logDebug) { Debug.Log("NetworkServerSimple accepted client:" + connectionId); } if (error != 0) { OnConnectError(connectionId, error); return; } string address; int port; NetworkID networkId; NodeID node; byte error2; NetworkManager.activeTransport.GetConnectionInfo(m_ServerHostId, connectionId, out address, out port, out networkId, out node, out error2); NetworkConnection conn = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass); conn.SetHandlers(m_MessageHandlers); conn.Initialize(address, m_ServerHostId, connectionId, m_HostTopology); conn.lastError = (NetworkError)error2; // add connection at correct index while (m_Connections.Count <= connectionId) { m_Connections.Add(null); } m_Connections[connectionId] = conn; OnConnected(conn); }
public void Connect(EndPoint secureTunnelEndPoint) { bool usePlatformSpecificProtocols = NetworkManager.activeTransport.DoesEndPointUsePlatformProtocols(secureTunnelEndPoint); PrepareForConnect(usePlatformSpecificProtocols); if (LogFilter.logDebug) { Debug.Log("Client Connect to remoteSockAddr"); } if (secureTunnelEndPoint == null) { if (LogFilter.logError) { Debug.LogError("Connect failed: null endpoint passed in"); } m_AsyncConnect = ConnectState.Failed; return; } // Make sure it's either IPv4 or IPv6 if (secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetwork && secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetworkV6) { if (LogFilter.logError) { Debug.LogError("Connect failed: Endpoint AddressFamily must be either InterNetwork or InterNetworkV6"); } m_AsyncConnect = ConnectState.Failed; return; } // Make sure it's an Endpoint we know what to do with string endPointType = secureTunnelEndPoint.GetType().FullName; if (endPointType == "System.Net.IPEndPoint") { IPEndPoint tmp = (IPEndPoint)secureTunnelEndPoint; Connect(tmp.Address.ToString(), tmp.Port); return; } if ((endPointType != "UnityEngine.XboxOne.XboxOneEndPoint") && (endPointType != "UnityEngine.PS4.SceEndPoint")) { if (LogFilter.logError) { Debug.LogError("Connect failed: invalid Endpoint (not IPEndPoint or XboxOneEndPoint or SceEndPoint)"); } m_AsyncConnect = ConnectState.Failed; return; } byte error = 0; // regular non-relay connect m_RemoteEndPoint = secureTunnelEndPoint; m_AsyncConnect = ConnectState.Connecting; try { m_ClientConnectionId = NetworkManager.activeTransport.ConnectEndPoint(m_ClientId, m_RemoteEndPoint, 0, out error); } catch (Exception ex) { if (LogFilter.logError) { Debug.LogError("Connect failed: Exception when trying to connect to EndPoint: " + ex); } m_AsyncConnect = ConnectState.Failed; return; } if (m_ClientConnectionId == 0) { if (LogFilter.logError) { Debug.LogError("Connect failed: Unable to connect to EndPoint (" + error + ")"); } m_AsyncConnect = ConnectState.Failed; return; } m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass); m_Connection.SetHandlers(m_MessageHandlers); m_Connection.Initialize(m_ServerIp, m_ClientId, m_ClientConnectionId, m_HostTopology); }
public bool ReconnectToNewHost(EndPoint secureTunnelEndPoint) { if (!NetworkClient.active) { if (LogFilter.logError) { Debug.LogError("Reconnect - NetworkClient must be active"); } return(false); } if (m_Connection == null) { if (LogFilter.logError) { Debug.LogError("Reconnect - no old connection exists"); } return(false); } if (LogFilter.logInfo) { Debug.Log("NetworkClient Reconnect to remoteSockAddr"); } ClientScene.HandleClientDisconnect(m_Connection); ClientScene.ClearLocalPlayers(); m_Connection.Disconnect(); m_Connection = null; m_ClientId = NetworkManager.activeTransport.AddHost(m_HostTopology, m_HostPort, null); if (secureTunnelEndPoint == null) { if (LogFilter.logError) { Debug.LogError("Reconnect failed: null endpoint passed in"); } m_AsyncConnect = ConnectState.Failed; return(false); } // Make sure it's either IPv4 or IPv6 if (secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetwork && secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetworkV6) { if (LogFilter.logError) { Debug.LogError("Reconnect failed: Endpoint AddressFamily must be either InterNetwork or InterNetworkV6"); } m_AsyncConnect = ConnectState.Failed; return(false); } // Make sure it's an Endpoint we know what to do with string endPointType = secureTunnelEndPoint.GetType().FullName; if (endPointType == "System.Net.IPEndPoint") { IPEndPoint tmp = (IPEndPoint)secureTunnelEndPoint; Connect(tmp.Address.ToString(), tmp.Port); return(m_AsyncConnect != ConnectState.Failed); } if ((endPointType != "UnityEngine.XboxOne.XboxOneEndPoint") && (endPointType != "UnityEngine.PS4.SceEndPoint")) { if (LogFilter.logError) { Debug.LogError("Reconnect failed: invalid Endpoint (not IPEndPoint or XboxOneEndPoint or SceEndPoint)"); } m_AsyncConnect = ConnectState.Failed; return(false); } byte error = 0; // regular non-relay connect m_RemoteEndPoint = secureTunnelEndPoint; m_AsyncConnect = ConnectState.Connecting; try { m_ClientConnectionId = NetworkManager.activeTransport.ConnectEndPoint(m_ClientId, m_RemoteEndPoint, 0, out error); } catch (Exception ex) { if (LogFilter.logError) { Debug.LogError("Reconnect failed: Exception when trying to connect to EndPoint: " + ex); } m_AsyncConnect = ConnectState.Failed; return(false); } if (m_ClientConnectionId == 0) { if (LogFilter.logError) { Debug.LogError("Reconnect failed: Unable to connect to EndPoint (" + error + ")"); } m_AsyncConnect = ConnectState.Failed; return(false); } m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass); m_Connection.SetHandlers(m_MessageHandlers); m_Connection.Initialize(m_ServerIp, m_ClientId, m_ClientConnectionId, m_HostTopology); return(true); }