I have a problem concerning local server and client. I'm writing a multiplayer game. Due to my design, all players connect via network to the server (even the local player). I found out, that if my server is running and then I connect to this local server from the same Unity-App, the server gets shut down (or at least the port gets closed).
Isn't it possible to run a Unity-Network Server and Client within the same Application and connect them to each other??
If not, how to handle this problem? Treating the local player differently than the other players would be my worst choice. I also don't want to use a dedicated server (that would be impossible for web-apps).
asked Mar 08 '10 at 12:53 PM
Unfortunately, it is not possible to do this all in one application.
Unity has two connection sockets: One for connecting to other players, and one for connecting to the master server.
When you host a server, it uses the player connection socket to host that server. Trying to connect to that server forces Unity to end that socket, in order to make a new socket to connect to the server. By removing the socket, it ends the server.
If this doesn't make sense, think of it this way, a socket is a connection, and you ahve tow connection slots.
Whenever you start connection one of these slots is used. Whatever was previously in that slot gets removed.
Despite intuition, joining, and hosting both use the same slot, so they cancel each other out.
Hope this helps -- Flynn.
Do note: Sockets are application reliant. If you run two SEPARATE applications, and make one host, and the other join, then it will work just fine.
answered Jan 17 '11 at 10:56 PM