Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    Dismiss Notice

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

Discussion in 'Multiplayer Networking' started by F-R-O-S-T-Y, Nov 14, 2017.

  1. F-R-O-S-T-Y

    F-R-O-S-T-Y

    Joined:
    Mar 22, 2013
    Posts:
    82
    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. F-R-O-S-T-Y

    F-R-O-S-T-Y

    Joined:
    Mar 22, 2013
    Posts:
    82
    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.