Sign in to follow this  
deltaKshatriya

Unity3d Basic Networking Issue

Recommended Posts

deltaKshatriya    2210

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 this post


Link to post
Share on other sites
CaseyHardman    2765

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.

Share this post


Link to post
Share on other sites
deltaKshatriya    2210

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 this post


Link to post
Share on other sites
CaseyHardman    2765

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 this post


Link to post
Share on other sites
deltaKshatriya    2210

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 this post


Link to post
Share on other sites
deltaKshatriya    2210

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this