Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Networking help? I can connect to a server but not load a level?

Discussion in 'Scripting' started by SameDev, Nov 16, 2013.

  1. SameDev

    SameDev

    Joined:
    Apr 14, 2013
    Posts:
    16
    I have recently worked on a small networking script to create a multiplayer fps. I managed to test in on my own pc, connect 2 instances of the application to a server created by one of them and spawn in a game level and play. However upon testing the game between 2 PCs it doesnt load up the level. Can anyone help me? It works fine on my own pc and it can connect to a server between two PCs but loading a game level wont work.
     
  2. Pirs01

    Pirs01

    Joined:
    Sep 30, 2012
    Posts:
    389
    Debug the code that loads up level and see what goes wrong with it.
     
  3. SameDev

    SameDev

    Joined:
    Apr 14, 2013
    Posts:
    16
    Ive debugged and I have the answer I think. The client cant connect to the host port. How would I go about doing that so that the port can be automatically cached somewhere and retrieved by the client?(assuming thats possible)
     
  4. Pirs01

    Pirs01

    Joined:
    Sep 30, 2012
    Posts:
    389
    Well, the server won't able to send anything to client like port number until the client connects and the client cannot connect without knowing the port number.

    If that's your problem then the easy solution is to make the port number constant at build time so it doesn't change and you don't have to send it.

    If that's not an option then you need one server with static ip:port (like for example a website that has the data in page content so you can retrieve it with HTML request for simple implementation) that mediates game server ip:port to clients. This way game server with dynamic ip:port can send it's ip:port to that mediatory server and then clients can retrieve that data from it. Both client and game server won't have trouble finding mediatory server because it's location is static.

    Typically the way games work is they have a lobby server at static location that holds information about all game servers that can be created by users for example. Client connects to lobby server whose location is static and retrieves list of game servers for user to pick one if he will.
     
    Last edited: Nov 18, 2013
  5. Pirs01

    Pirs01

    Joined:
    Sep 30, 2012
    Posts:
    389
    Also when you talk about ports and connection problems. The stock Unity networking doesn't handle punching-through well if I recall correctly. So even if you have the port you still might have problems connecting and solution to this goes beyond Unity coding. You might be better off using third party networking solution. I would suggest uLink because it's very tightly integrated into Unity.
     
    Last edited: Nov 18, 2013