Search Unity

Connection to server fails often when when multiple devices in the same network.

Discussion in 'Multiplayer' started by Wattosan, Nov 14, 2017.

  1. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    460
    Hey,

    I've come across a weird problem. I've some data I need to send to the server and then receive a response.
    I am currently testing a multiplayer game (PUN) where the player needs to login. The login information (with or without a facebook token) is sent to the server. When all is good, a response is received and the player has logged in.

    All is good when 2 test devices are on a different network (one is my wifi and the other one 4G). One of the players tries to send a login request to server using the WWW class. After one of the players has done it, I send the same request to the server on another device. I get the response and all is well.

    However, when both devices are on the same network (my wifi), then the problem goes like this:
    1) I try to login on one of the devices. WWW request is sent, and response successfully received. The player is logged in.
    2) I press the login button on the second device, and when the WWW request is formed, then after calling:

    Code (CSharp):
    1. wwwReq = new WWW(reqUrl, postData, headers);
    2. yield return wwwReq;
    3. OnRequestCompleted(requestCallback);
    , the WWW takes its time and finally calls the requestCallback. In the callback I detect that the WWW object has an error "Cannot connect to destination host". This occurs ONLY when someone has already logged in, and is in the same network. This never occurs on the device that tries to login first.
    Also, sometimes this problem does not occur and the login happens immediately on the second device. Sometimes it takes 3-4 retries and the login is a success (reconnect will happen immediately after receiving the connection error).

    Another peculiar thing to note is that when I use 3 devices to test, the first one still logs in perfectly, but...
    If, after many retries (or rarely immediately), the login is a success, then both devices (2 out of 3) login at the same time. It's like they both can suddenly reach the destination host.

    PS. There's no difference whether the devices are all connected to wifi or 4G. The problem persists in both cases.

    Any help is much appreciated!
     
  2. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    460
    A little update....the failed request actually does reach the server. And server sends everything back correctly as well. However, the response does not get back to the game.