[HELP]about remote connection problem

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

charles
Posts: 13
Joined: 23 Feb 2013, 09:08

[HELP]about remote connection problem

Postby charles » 23 Feb 2013, 14:38

Hi,this is my first post,and My English was so poor ,pardon me! :)

I use SFS_PRO(1.6.6) and Unity (4.0.1)

Server IP is 140.128.80.150 (at school)
gateway is 140.128.80.254

Client code using C#:

Code: Select all

public class LoginGUI : MonoBehaviour {
   private SmartFoxClient sfc;

   public string serverIP = "140.128.80.150";
   public int serverPort = 9339;
   public string zone = "city";
   public bool debug = true;

   private string username = "charles";
   private string password = "123456789";
   private string loginErrorMessage = "";

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

   void OnApplicationQuit() {
      try{sfc.Logout();
      sfc.Disconnect();
      }catch{}
      
   }

   void Awake() {
      Application.runInBackground = true;

      if ( SmartFox.IsInitialized() ) {
         sfc = SmartFox.Connection;
      } else {
         try {
            sfc = new SmartFoxClient(debug);
         sfc.runInQueueMode=true;
         } catch ( Exception e ) {
            loginErrorMessage = e.ToString();
         }
      }

      // Register callback delegate
      SFSEvent.onConnection += OnConnection;
      SFSEvent.onConnectionLost += OnConnectionLost;
      SFSEvent.onExtensionResponse += OnExtensionResponse;
      SFSEvent.onRoomListUpdate += OnRoomList;
     SFSEvent.onLogin+=OnLogin;
      SFSEvent.onDebugMessage += OnDebugMessage;

      sfc.Connect(serverIP, serverPort);
   }
   void FixedUpdate() {
      sfc.ProcessEventQueue();
   }
   
   void OnGUI() {
      try{
      if ( sfc.IsConnected() ) {
         // Login
         float centerX=Screen.width/2;
         float centerY=Screen.height/2;
         GUI.Box(new Rect(centerX-150,centerY-100,300,200),"");
         GUI.Label(new Rect(centerX-100, centerY-50, 100, 100), "Userame: ");
         username = GUI.TextField(new Rect(centerX-20,centerY-50, 150, 20), username, 25);

         GUI.Label(new Rect(centerX-100,centerY, 100, 100), "Password: ");
         password = GUI.PasswordField(new Rect(centerX-20,centerY, 150, 20), password, '*',16);

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

         if ( GUI.Button(new Rect(centerX-50, centerY+50, 100, 30), "Login") ) {
            sfc.Login(zone, username, password);
         }
      } else {
         GUI.Label(new Rect(10, 100, 100, 100), "Waiting for connection");
         GUI.Label(new Rect(10, 130, 100, 100), loginErrorMessage);
      if(GUI.Button (new Rect(10,200,100,30),"reconnect"))
            {sfc.Connect(serverIP, serverPort);   
               loginErrorMessage="";
            }
      }
      }catch{
         sfc.Disconnect();
         Application.Quit();
      }
      if(sfc.myUserId!=-1)
         Application.LoadLevel("Lobby");
   }


but, I tried to use AdminTool to connect , It is work! :?
Why? Please someone Can me?
If I lost trails ,I will supply soon.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: [HELP]about remote connection problem

Postby rjgtav » 24 Feb 2013, 23:50

Hello, welcome to the forums :)

It seems to me that the 140.128.80.150 IP you're using to connect is the internal IP (the IP attributed by the router), correct?
If so, then you should only be able to connect from computers which are on the same network. Is the machine where you're running the application on the school network?
If not, then you will have to use the school's external IP, which is the one given by http://whatismyip.org/

Thanks
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
charles
Posts: 13
Joined: 23 Feb 2013, 09:08

Re: [HELP]about remote connection problem

Postby charles » 25 Feb 2013, 08:26

Thanks for your response !! :D

It seems to me that the 140.128.80.150 IP you're using to connect is the internal IP (the IP attributed by the router), correct?

I don't know whether the IP attributed by the router or not.
How to check it?

Is the machine where you're running the application on the school network?

Yes, the other computer in the same network,IP is 140.128.80.142
BUT, I don't understand that AdminTool CAN connect the server.
,and the game made in Unity was not.

I check the server computer IP by http://whatismyip.org/ --> 140.128.80.150(same)
User avatar
zachofthegolden1
Posts: 89
Joined: 05 Sep 2011, 19:31

Re: [HELP]about remote connection problem

Postby zachofthegolden1 » 25 Feb 2013, 14:08

charles wrote:Thanks for your response !! :D

It seems to me that the 140.128.80.150 IP you're using to connect is the internal IP (the IP attributed by the router), correct?



Is the machine where you're running the application on the school network?

Yes, the other computer in the same network,IP is 140.128.80.142
BUT, I don't understand that AdminTool CAN connect the server.
,and the game made in Unity was not.

I check the server computer IP by http://whatismyip.org/ --> 140.128.80.150(same)



is your firewall preventing port 9339 and 8080 from being used? or ha your router been setup so ports 9339 and 8080 are forwarded? This might be the possible problem. Also if your admin tool connects is it using the ip 127.0.0.1?
-ZG1
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: [HELP]about remote connection problem

Postby rjgtav » 25 Feb 2013, 23:41

Hi,

If you're connecting from outside the school's network (like from your home) you have to use the IP provided by the website I posted up there.
If you're connecting from another computer inside the school's network you have to connect through the Internal IP of the machine which is running the server. You can find it by running the ipconfig command (if you're on Windows. On MAC I don't know but Google may help you) on the server machine, which will display a list of IPs attributed to the computer.

Please note that if you're connecting from outside the network, as zachofthegolden1 pointed out, you'll have to set up your school's router so that it forwards the incoming traffic on port 9339 to the machine which is running SFS.

Hope this helps
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
charles
Posts: 13
Joined: 23 Feb 2013, 09:08

Re: [HELP]about remote connection problem

Postby charles » 26 Feb 2013, 11:35

https://www.box.com/s/i1ckxczhuhinziet6gq8
the photo of AdminTool connected the server.

https://www.box.com/s/kmf0s70aansen14kdy1i
the server side result that running ipconfig command

P.S. using function "Img" didn't show the photo

I will try to set firewall :)
hopping I will success :D
thanks your advice rjgtav zachofthegolden1
charles
Posts: 13
Joined: 23 Feb 2013, 09:08

Re: [HELP]about remote connection problem

Postby charles » 26 Feb 2013, 12:19

OH ,

I can connect the Server suddenly!!!
my original client code var "serverIP" set "140.128.80.150";
but , print var "serverIP" became "127.0.0.1" :!:
so,I modify the code

public string serverIP = "140.128.80.150"
to
public const string serverIP = "140.128.80.150"

It's WORK!!
but , thank you again :D
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: [HELP]about remote connection problem

Postby rjgtav » 26 Feb 2013, 20:24

Hmm that's strange, using a variable or a constant should not cause any problems, maybe an Unity Client API issue?
I'll report it to the team.

Thanks
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 19 guests