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.