- Home /
How can I connect to an external server using Network.Connect?
I'm trying to figure out the best method to connect my project to the outside world, I started by writing both, the client and the server in Unity, however in the process I learned that I needed a MasterServer in order to make it work, after some research I found the source code of the MasterServer, downloaded it and built it and everything ran OK, but I don't feel comfortable with this solution, mainly because having two related interdependent servers running on the same hardware feels like an unnecessary waste.
So I switched to System.Net.Sockets, and after a while every thing worked fine, however when I tried to build my project for Android, the compiler complaints: "System.Net.Sockets" is only supported on Android Pro... the message is not very clear but I suppose this means I need the "Pro licence", so I moved the server code to a separated project on Visual Studio, and I'm now trying to connect to it, but I just cannot establish the connection with Network.Connect.
The server is running fine, it does accept connections from a test client I wrote, while Unity keeps telling me "The connection request to 192.168.56.1:2500 failed. Are you sure the server can be connected to?"... the accept process on the server is not triggered, meaning no socket connection was received. To discard an error on my code I tested with a remote web server under my control but still get the same message, and the accept process on the remote server is not triggered either. Finally I typed "192.168.56.1:2500" on my web browser and in this case the accept process does get triggered on the my server project, confirming my code is correct... so there must be something weird in the way Network.Connect handles the communication, but can figure out what it is.
Any ideas/advise?
What kind of server are you setting up with Sockets
Unity's networking system expects a very specific type of server. Generally if you want to use Unity's Networking system you need to use the $$anonymous$$asterServer
.