Unity3d Basic Networking Issue

Started by
4 comments, last by warhound 11 years, 2 months ago

So I've been trying to connect a client to a server in Unity3d. When the client tries to connect to the server, after some time, an error comes up that the system is already connected. I'm not entirely sure what could cause this. Any help? Thanks in advance.

No one expects the Spanish Inquisition!

Advertisement

Are you trying to connect more than once? That could happen if the call to Network.Connect() is inside an Update() function.

To see if you've made a connection already, try this:

UnityScript:


function OnConnectedToServer() //This is called when you successfully connect with the server
{
   Debug.Log("Connected to the server.");
}

C#:


void OnConnectedToServer()
{
  Debug.Log("Connected to server.");
}

Then you'll be able to tell in the Console window if you've made a connection already.

Alternatively, when you call Network.Connect(), you could put a Debug.Log("Attempting to connect to the server"); before it. If you see it more than once, then you know something's wrong.

[twitter]Casey_Hardman[/twitter]

That's actually the issue, the console never shows a successful connection...and I tried checking within a OnConnectedToServer function as well, but it seems that client never connects...

EDIT:

Also, run in background is enabled, so that's not interfering either...

No one expects the Spanish Inquisition!

That's odd...

You're calling Network.InitializeServer() on the server and Network.Connect() on the client, both using the same port, right? Are they both running separate Unity projects (e.g. OnlineGameClient project is trying to connect to OnlineGameServer)? Or are you trying to make a game where a certain player hosts the game for other players, like Warcraft III, instead of using a dedicated server?

The issue could be related to the port number you're using with Network.Connect(). Have you tried changing it yet? If you are, remember to change the port of InitializeServer() AND Connect() to the same value.

If you still can't get it to work, please post the code you're using to Connect() and InitializeServer(), and the full error message you're getting in the Console (you can copy from the Console with CTRL+C and paste here).

[twitter]Casey_Hardman[/twitter]

The program is really just a simple connect to the server program, where one project hosts and the other tries to connect. I tried doing separate projects as well, and the eror that comes up is that the client is banned from connecting. I have not tried changing the port number yet, so maybe that will make a difference.

No one expects the Spanish Inquisition!

Alright, I figured it out, the Network.InitializeServer was being called over and over again. So I got the system to connect, but it only connects to my computer on the local network. Why would the system be unable to connect from a different network? Thanks in advance for any help.

No one expects the Spanish Inquisition!

This topic is closed to new replies.

Advertisement