Unity: connection lost / no connection to server

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

MirrorsEdge
Posts: 6
Joined: 09 Feb 2011, 22:00

Unity: connection lost / no connection to server

Postby MirrorsEdge » 09 Feb 2011, 22:22

Hi

I have a little problem with unity when running my game. I'm specifically talking about the login example, LoginGUI of the Island demo. When I hit run, I can get past the connect box with my external ip and port - no problem, but when entering a username it says 'waiting for connection' and then the error message; 'connection lost / no connection to server' is displayed.

I have configured the server correctly, and opened all the ports in my routers page (9339, 8080 to my LAN IP). I even tested telnet on my external ip and port and it returns the cross domain policy message. I also have the security policy setup.

Running it locally works, but I want people outside my network to access my game as well. Any idea what the problem could be?

Note: Running SFS PRO 1.6.6 in Unity 3.0 :?:
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 09 Feb 2011, 23:08

Did you use your external IP address for your client swf?
Smartfox's forum is my daily newspaper.
MirrorsEdge
Posts: 6
Joined: 09 Feb 2011, 22:00

Postby MirrorsEdge » 10 Feb 2011, 09:53

Client SWF? You mean the Unity game? Yes, I did. I changed the script in the inspector to my external ip and port.

Would I have to put my unity directory into the same directory as the server in program files, or it wouldn't make a difference?

Edit: I forgot to mention, this error happens within the Unity editor as well.
MirrorsEdge
Posts: 6
Joined: 09 Feb 2011, 22:00

Postby MirrorsEdge » 10 Feb 2011, 15:34

Could it be a problem with my ports/firewall? Because when I put my unity webplayer on the Jetty web server, I can access it via http://"ExternalIP":8080/WebPlayer but it can't load the game. I can observe from the status bar it says 'Waiting for "MyIP"...' The Unity logo eventually comes up but can't progress any further.

Image to illustrate: http://i.imgur.com/Rd6yl.png

:?
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 10 Feb 2011, 22:29

Hrm...

When I hit run, I can get past the connect box with my external ip and port - no problem, but when entering a username it says 'waiting for connection' and then the error message; 'connection lost / no connection to server' is displayed.


Is what confuses me. You're saying that you were able to connect, but after logging in - you get no response following by connection lost.

It sounds as if you encountered a problem during the login stage (i.e. a server error) and then possibly disconnected due to MaxSocketIdleTime.

Did you get any error on server side? Can you confirm that the server received the login request? You can check this by turning on DebugIncomingMessage.
Smartfox's forum is my daily newspaper.
MirrorsEdge
Posts: 6
Joined: 09 Feb 2011, 22:00

Postby MirrorsEdge » 10 Feb 2011, 23:01

Yes, I can get past the connect stage which brings me to the username login. I enter a username, hit enter, and it waits here for maybe 10 seconds before displaying that error.

I turned on DebugIncomingMessage. Here's what I got:

Code: Select all

2011/02/11 00:25:12.035 - [ INFO ] [id: 11] (Logger.logInfo): [RedBox] Internal event received: serverReady
2011/02/11 00:25:12.038 - [ INFO ] [id: 11] (Logger.logInfo): [RedBox] Internal event received: serverReady
2011/02/11 00:25:12.040 - [ INFO ] [id: 11] (Logger.logInfo): [RedBox] Internal event received: serverReady
2011/02/11 00:25:51.449 - [ INFO ] [id: 12] (SmartFoxServer.readIncomingMessages): { DATA IN } : <policy-file-request/>
2011/02/11 00:25:53.109 - [ INFO ] [id: 12] (SmartFoxServer.readIncomingMessages): { DATA IN } : <msg t='sys'><body action='verChk' r='0'><ver v='160' /></body></msg>


Unity:

Code: Select all

Platform assembly: C:\Program Files (x86)\Unity\Editor\Data\Managed\CrossDomainPolicyParser.dll (this message is harmless)
SocketPolicyClient1: Incoming GetPolicyStreamForIP

Platform assembly: C:\Program Files (x86)\Unity\Editor\Data\Mono\lib\mono\2.0\System.Configuration.dll (this message is harmless)
SocketPolicyClient1: About to BeginConnect to *IP*:9339

SocketPolicyClient1: About to WaitOne

SocketPolicyClient1: Socket connected

Policy for host *IP* found in the cache.
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 11 Feb 2011, 00:15

There is no indication that you sent the login request. Maybe that's where the problem is..?
Smartfox's forum is my daily newspaper.
MirrorsEdge
Posts: 6
Joined: 09 Feb 2011, 22:00

Postby MirrorsEdge » 11 Feb 2011, 15:19

I have no idea.

The login does work when I point my client to my LAN IP though. Why would it not work when I set it up to connect to my external IP?

Here's the LoginGUI script. Maybe I have done something wrong?

Code: Select all

using UnityEngine;
using System;
using System.Collections;
using SmartFoxClientAPI;
using SmartFoxClientAPI.Data;
using SmartFoxClientAPI.Util;
using System.Security.Permissions;

public class LoginGUI : MonoBehaviour {
   private SmartFoxClient smartFox;
   private bool shuttingDown = false;
   private string serverIP = "*IP*";
   private string serverPort = "9339";
   private int Port = 9339;
   public string zone = "simpleChat";
   public bool debug = true;

   public GUISkin gSkin;

   private string username = "";
   private string loginErrorMessage = "";

   /************
     * Unity callback methods
     ************/

   void OnApplicationQuit() {
      shuttingDown = true;
   }

   private bool connectionAttempt = false;

   void Awake() {
      Application.runInBackground = true;
      
      if ( SmartFox.IsInitialized() ) {
         smartFox = SmartFox.Connection;
      } else {
         Security.PrefetchSocketPolicy(serverIP, Port);
         try {
            smartFox = new SmartFoxClient(debug);
            smartFox.runInQueueMode = true;
         } catch ( Exception e ) {
            loginErrorMessage = e.ToString();
         }
      }

      // Register callback delegate
      SFSEvent.onConnection += OnConnection;
      SFSEvent.onConnectionLost += OnConnectionLost;
      SFSEvent.onLogin += OnLogin;
      SFSEvent.onRoomListUpdate += OnRoomList;
      SFSEvent.onDebugMessage += OnDebugMessage;
      
   }
   
   void FixedUpdate() {
      smartFox.ProcessEventQueue();
   }

   void OnGUI() {

      GUI.skin = gSkin;
      GUI.Label(new Rect(2, -2, 680, 70), "");   

      if (!connectionAttempt) {
         GUI.Label(new Rect(10, 116, 100, 100), "IP: ");
         serverIP = GUI.TextField(new Rect(100, 116, 200, 20), serverIP, 25);
         
         GUI.Label(new Rect(10, 136, 100, 100), "Port: ");
         serverPort = GUI.TextField(new Rect(100, 136, 200, 20), serverPort, 25);
         
         if (GUI.Button(new Rect(100, 166, 100, 24), "Connect")  || (Event.current.type == EventType.keyDown && Event.current.character == '\n')) {
            connectionAttempt = true;
            smartFox.Connect(serverIP, Convert.ToInt32(serverPort));
         }
      
      }
      else if (smartFox.IsConnected()) {
         // Login
         GUI.Label(new Rect(10, 116, 100, 100), "Username: ");
         username = GUI.TextField(new Rect(100, 116, 200, 20), username, 25);

         GUI.Label(new Rect(10, 218, 100, 100), loginErrorMessage);

         if ( GUI.Button(new Rect(100, 166, 100, 24), "Login")  || (Event.current.type == EventType.keyDown && Event.current.character == '\n')) {
            smartFox.Login(zone, username, "");
         }

      } else {
         GUI.Label(new Rect(10, 150, 100, 100), "Waiting for connection");
         GUI.Label(new Rect(10, 218, 100, 100), loginErrorMessage);
      }
   }

   /************
    * Helper methods
    ************/

   private void UnregisterSFSSceneCallbacks() {
      // This should be called when switching scenes, so callbacks from the backend do not trigger code in this scene
      SFSEvent.onConnection -= OnConnection;
      SFSEvent.onConnectionLost -= OnConnectionLost;
      SFSEvent.onLogin -= OnLogin;
      SFSEvent.onRoomListUpdate -= OnRoomList;
      SFSEvent.onDebugMessage -= OnDebugMessage;
   }

   /************
    * Callbacks from the SFS API
    ************/

   void OnConnection(bool success, string error) {
      if ( success ) {
         SmartFox.Connection = smartFox;
      } else {
         loginErrorMessage = error;
      }
   }

   void OnConnectionLost() {
      loginErrorMessage = "Connection lost / no connection to server";
   }

   public void OnDebugMessage(string message) {
      Debug.Log("[SFS DEBUG] " + message);
   }

   public void OnLogin(bool success, string name, string error) {
      if ( success ) {
         // Lets wait for the room list

      } else {
         // Login failed - lets display the error message sent to us
         loginErrorMessage = error;
      }
   }

   void OnRoomList(Hashtable roomList) {
      // When room list is updated we are ready to move on to the island
      UnregisterSFSSceneCallbacks();
      Application.LoadLevel("Scene");
   }
}
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 11 Feb 2011, 17:24

Try setting the MaxSocketIdleTime value to something high in your config.xml file. Does the problem still persists?

Have you tried accessing your game outside your network?
Smartfox's forum is my daily newspaper.
MirrorsEdge
Posts: 6
Joined: 09 Feb 2011, 22:00

Postby MirrorsEdge » 11 Feb 2011, 21:28

BigFIsh wrote:Try setting the MaxSocketIdleTime value to something high in your config.xml file. Does the problem still persists?

Yes it does.
BigFIsh wrote:Have you tried accessing your game outside your network?

I got a friend to try. He said he connected but couldn't enter his username. :?
User avatar
Lapo
Site Admin
Posts: 20048
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 14 Feb 2011, 09:03

Moved to the correct forum.
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 1 guest