private IEnumerator sendPingRequest() { while (true) { // wait PING_REQUEST_TIME yield return new WaitForSeconds(PING_REQUEST_TIME); // send ping request ClientNET_SendFunction.sendPing(); // Debug.Log("sending ping request"); } }
private IEnumerator updatePlayerPos() { // wait until player connects yield return new WaitUntil(() => client.getPlayerFromClientID(client.clientID) != null); player = client.getPlayerFromClientID(client.clientID).GetComponent<Player>(); while (true) { // wait RESET_POS_TIME yield return new WaitForSeconds(RESET_POS_TIME); // broadcast position of player ClientNET_SendFunction.SendPositionRotationY(player.transform.position, player.transform.eulerAngles.y); // broad Cast new position // Debug.Log("setting " + player + " to pos:" + player.transform.position + " and rotY to:" + player.transform.rotation.y); } }
/*--------------------------------------*/ // send position, rotation & input to server private void NetMovementUpdate(int key) { ClientNET_SendFunction.SendMovement(transform.position, transform.eulerAngles.y, key); }
public void init() { // protocol init NetworkTransport.Init(); ClientNET_RecieaveFunction.init(this); ClientNET_SendFunction.init(this); ConnectionConfig cc = new ConnectionConfig(); reliableChanel = cc.AddChannel(QosType.Reliable); // ReliableSequenced, Reliable unReliableChanel = cc.AddChannel(QosType.Unreliable); HostTopology topo = new HostTopology(cc, MAX_USER); hostId = NetworkTransport.AddHost(topo, 0); /*--------------------------------------------------*/ Debug.Log(ServerHost); ConnectionMenu.setConnectionStatusMessage("connecting to " + ServerHost); if (ServerHost != "localhost" && ServerHost != "127.0.0.1") // FIXME: check if is on local area // check if player is connected { try { IPAdress = System.Net.Dns.GetHostEntry("google.com").AddressList[0].ToString(); ConnectionMenu.setConnectionStatusMessage("Checking connection status."); Debug.Log("Checking connection status."); } catch (System.Exception e) { ConnectionMenu.setConnectionStatusMessage("error: you are not connected to the internet."); Debug.Log("error: you are not connected to the internet."); disconnect(); // disconnect client } } // resolve hostname try { IPAdress = System.Net.Dns.GetHostEntry(ServerHost).AddressList[0].ToString(); ConnectionMenu.setConnectionStatusMessage("Resolving hostname " + ServerHost); canConnect = true; } catch (System.Exception e) { ConnectionMenu.setConnectionStatusMessage("error: hostname " + ServerHost + " dosen't exist"); Debug.Log("error: hostname " + ServerHost + "dosen't exist"); disconnect(); // disconnect client } /*--------------------------------------------------*/ if (canConnect) { // try to connect connectionId = NetworkTransport.Connect(hostId, IPAdress, PORT, 0, out error); Debug.Log("try to connect to " + ServerHost + " | " + IPAdress + ":" + PORT); ConnectionMenu.setConnectionStatusMessage("Connecting to " + ServerHost + ":" + PORT + "..."); if (error != 0) { Debug.Log("can't connect to server | error: " + error + " | retriying..."); ConnectionMenu.setConnectionStatusMessage("can't connect to server | error: " + error + " | retriying..."); init(); } else { isStarted = true; } } }