• 9
• 9
• 10
• 9
• 10

# Unity3d Basic Networking Issue

This topic is 1904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites

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

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.

##### Share on other sites

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...

Edited by kryotech

##### Share on other sites

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).

Edited by Sir Mac Jefferson

##### Share on other sites

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.

##### Share on other sites

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.