Cannot connect to server..?

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

CTucker1327
Posts: 8
Joined: 23 Oct 2013, 01:30

Cannot connect to server..?

Postby CTucker1327 » 23 Oct 2013, 08:27

Hello, this will be my first-post here on the forums and I would like to start off by thanking the developers for this stand-alone server, it's saved me tons of heart-ache and learning, even if it was just by providing some basics. (Atleast, the basics are all that I have ventured into so-far :P)

I'd like to start off by apologizing for all of the "Code segments" etc listed here, however it's just to show why I believe I have a problem, the jist of it is, I cannot connect using my PublicIP for SmartFox ONLY, It's fully port-forwarded and not blocked by anything.


Here's my issue...

I'm developing a game in Unity3D, I'm not what you would call an "Experienced" developer but I dedicate tons of time into learning programming and trying to better my practices, I'm currently in the progress of trying to write a basic chat application using SmartFoxServer, albeit I'm running into a fairly strange issue. I cannot connect to the server, well I can, but I can't.

What I mean by this is, I can connect on localhost fine, which is normal, however if I try to connect through my public IP address I cannot, and in return, my friends cannot connect to me either, I have successfully port-forwarded and have hosted numerous applications throughout my life, so I'm well aware of the port-forwarding process, I don't have anything blocking my ports either, as far as I can tell, fire-walls and anti-viruses are all disabled (Not even installed, honestly)

Here's where it get's strange.

After getting agitated that I couldn't connect to the server via a public IP, but determined that I had everything set-up correctly, I wrote a very basic stand-alone server application in Java [Source Code Below]

Code: Select all

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Main implements Runnable {

    ServerSocket _serverSocket;
    Socket _socket;

    public Main() {
        try {
            System.out.println("Starting Server");
            _serverSocket = new ServerSocket(9933);
        } catch (IOException e) {
            System.out.println("Startup Failed");
            e.printStackTrace();
        }
    }

    public void run() {
        while(true) {
            try {
                _socket = _serverSocket.accept();
                String connectingHost = _socket.getInetAddress().getHostName();
                System.out.println("Connection from " + connectingHost);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String args[]) {
        new Thread(new Main()).start();
    }
}



Now, I ran this server which (if you have any programming experience) you can see that is hosted on port: 9933 (Same as the SmartFoxServer) and attempted to connect to it using my Unity3D application... all of a sudden it connects just fine and I get the following message in my console:

Connection from 50.**.**.110



So, I don't understand why it's not finding the Smart-Fox-Server on anything besides localhost, when I attempt to connect to it via the public IP it's like it's not even visible, the server never receives the clients connection, however by writing my own basic server to monitor a connection through the public IP, I can see very easily that it's not a port issue.

Perhaps there's some configurations I'm missing, anybody have a clue?


EDIT: Here's some more information, that seems rather strange to me... It doesn't matter what I have the port set to if I'm connecting via LocalHost, last I checked, even for localhost this should matter, so I'm going to post my connection code.

Code: Select all

   public void connect(string _host, string _port, string _user, string _pass) {
      this.userName = _user;
      this.passWord = _pass;
      
      var port = int.Parse(_port);
      Debug.Log("Attempting to contact server on " + _host + ":"+_port);
      _client.Connect(_host, port);
   }


and that is called from my GUIManager class, using this code

Code: Select all

         if(GUI.Button (new Rect(730, 425, 180, 65), "Login")) {
            _connection.connect(_host, _port, _user, _pass);
         }



I also tossed together a basic connection, shown here:

Code: Select all

using UnityEngine;
using System.Collections;
using Sfs2X;
using Sfs2X.Core;
using Sfs2X.Requests;
using Sfs2X.Entities;

public class Test : MonoBehaviour {
   
   public Texture _texture;
   SmartFox _client;
   
   // Use this for initialization
   void Start () {
      _client = new SmartFox();
      _client.ThreadSafeMode = true;
      _client.AddEventListener(SFSEvent.CONNECTION, OnConnection);
      _client.Connect("50.**.**.110", 9933);
   }
   // Update is called once per frame
   void Update () {
   }
   
   void FixedUpdate() {
      _client.ProcessEvents();
   }

   void OnGUI() {
      
   }
   
      
   void OnConnection(BaseEvent _event) {
      if((bool)_event.Params["success"]) {
         Debug.Log ("Connection success");
      } else {
         Debug.Log ("Connection failed");
      }
   }
}


However, it prints "Connection failed" and the SmartFox server doesn't see anything, but while running my server that I provided the source to above (Which is the most basic of servers) shows that a connection is received.
CTucker1327
Posts: 8
Joined: 23 Oct 2013, 01:30

Re: Cannot connect to server..?

Postby CTucker1327 » 23 Oct 2013, 11:52

Added more information, tested some more things, still having the problems, added the Test class that I used to try to see if I just messed something up, as-well.
CTucker1327
Posts: 8
Joined: 23 Oct 2013, 01:30

Re: Cannot connect to server..?

Postby CTucker1327 » 25 Oct 2013, 05:13

Bump
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Cannot connect to server..?

Postby Bax » 25 Oct 2013, 06:16

What I mean by this is, I can connect on localhost fine, which is normal, however if I try to connect through my public IP address I cannot, and in return, my friends cannot connect to me either, I have successfully port-forwarded and have hosted numerous applications throughout my life, so I'm well aware of the port-forwarding process, I don't have anything blocking my ports either, as far as I can tell, fire-walls and anti-viruses are all disabled (Not even installed, honestly)

Did you configure SFS2X to bind the private IP of the server (to which the public IP should be forwarded)?
You have to do it in the Server Configurator module of the Admin Tool.
Paolo Bax
The SmartFoxServer Team
CTucker1327
Posts: 8
Joined: 23 Oct 2013, 01:30

Re: Cannot connect to server..?

Postby CTucker1327 » 30 Oct 2013, 15:46

Thanks Bax, I was trying to set it to the Public IP instead of the Private IP, that was my problem.

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 19 guests