Search Unity

NetworkTransport : Cannot open socket on ip {*} and port {25000}

Discussion in 'Multiplayer' started by Reizla, May 18, 2016.

  1. Reizla

    Reizla

    Joined:
    Nov 5, 2013
    Posts:
    136
    I'm getting the following error "Cannot open socket on ip {*} and port {25000}; check please your network, most probably port has been already occupied" on my PC when testing the server AND client on one machine (the Linux machine needs to be reformatted that's why I'm only using one PC now) and am wondering if it's possible to allow multiple games to use one socket/port in Unity's NetworkTransport...

    The code I've used it pretty basic from what the documentation shows and so far I'm only testing how and what with server-client connections. But IMO a socked should not be locked to one application running and has to be shared. So pretty simply pot - how to share that socket..?
     
  2. Oshroth

    Oshroth

    Joined:
    Apr 28, 2014
    Posts:
    99
    You can't share a port, because otherwise the OS wouldn't be able to direct network traffic to the correct application.

    Can you explain more about what you are trying to do and how you are setting up the connections?

    You generally don't specify a port for client sockets (i.e. addHost(Topology) is fine and will use a random free port). You only need to specify the port for the server socket and when clients are connecting to it. Clients don't need to have a socket with the same port as the server they are connecting to.
     
  3. BIG-BUG

    BIG-BUG

    Joined:
    Mar 29, 2009
    Posts:
    457
    Usually each application instance is bound exclusively to one socket/port. I think almost all network APIs work that way.
    There are some "low level" tricks to have multiple applications listening to one port, but probably not in Unity's regular API.

    This means for you:
    At least the client instances of your game have to use a dynamic port (port = 0).
    For the host instance a defined port may be used (so the clients know to which port to connect). (You might want to allow the user to override the "default" port for the host as well).
     
  4. Reizla

    Reizla

    Joined:
    Nov 5, 2013
    Posts:
    136
    Thanks Oshroth and BIG BUG. Gotta say that I find this low level API pretty fuzzy (also from the lack of documentation) and I'll get back on (learning) the HLAPI. There I managed to use the game's port 27 times on my machine. I only have to figure out what the best way is to make a server that'll use several instances for different players and how to visualize it (on demand).
     
  5. Oshroth

    Oshroth

    Joined:
    Apr 28, 2014
    Posts:
    99
    Have a look at Good Enough Guide To LLAPI. It does a reasonable job of explaining the LLAPI. I also recommend looking up how other non-unity socket-based applications handle separate users, web servers and chat systems for example.
     
  6. Reizla

    Reizla

    Joined:
    Nov 5, 2013
    Posts:
    136
    Thanks for sharing the link, but it's basically the same as what the Unity docs tell about the topic. Moreover, the replies show that other people have the same problem with sharing ports as I have without any solution to the problem :(

    By now I've decided to head back to the HLAPI, which is able to share ports.