I have used SFS Overcast successfully with SSL. Currently for some reasons I am moving to a personal server. However, getting an error with SSL. I installed SFS2x on Google cloud Linux, added SSL and opened port for 8443. I was able to access the admin page domain.com/8443:admin. but cannot connect from SFS Unity Client.
Below is my configuration, please take a look and can you give me some guidance? Thank you,
// Reset buddy chat history BuddyChatHistoryManager.Init();
// Show connection lost message, in case the disconnection occurred in another scene string connLostMsg = gm.ConnectionLostMessage; if (connLostMsg != null) errorText.text = connLostMsg; }
//---------------------------------------------------------- // UI event listeners //---------------------------------------------------------- #region /** * On username input edit end, if the Enter key was pressed, connect to SmartFoxServer. */ public void OnNameInputEndEdit() { if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)) Connect(); }
/** * On Login button click, connect to SmartFoxServer. */ public void OnLoginButtonClick() { Connect(); } #endregion
// Initialize SmartFox client // The singleton class GlobalManager holds a reference to the SmartFox class instance, // so that it can be shared among all the scenes #if !UNITY_WEBGL sfs = gm.CreateSfsClient(); #else sfs = gm.CreateSfsClient(UseWebSocket.WS_BIN); #endif
private void OnConnection(BaseEvent evt) { // Check if the conenction was established or not if ((bool)evt.Params["success"]) { Debug.Log("SFS2X API version: " + sfs.Version); Debug.Log("Connection mode is: " + sfs.ConnectionMode);
sfs.InitCrypto();
// Login //sfs.Send(new LoginRequest(nameInput.text)); } else { // Show error message errorText.text = "Connection failed; is the server running at all?";
Hi, your client supports both socket and websockets connections. Are both failing? If so can you provide the exact error you're getting and specify which connection type you're testing with?
Also, when using websockets the InitCrypto step should be skipped entirely as it's not needed.
In addition, I use TCP sockets to connect. Is the control panel configured to open port 8443? Even though I tried opening it, I couldn't connect from the client. going to the web console with SSL still succeeds.
using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;
using Sfs2X; using Sfs2X.Core; using Sfs2X.Requests; using Sfs2X.Util;
/** * Script attached to the Controller object in the Login scene. */ public class LoginSceneController : BaseSceneController { //---------------------------------------------------------- // Editor public properties //----------------------------------------------------------
[Tooltip("IP address or domain name of the SmartFoxServer instance")] private string host = "domain.com";
[Tooltip("TCP listening port of the SmartFoxServer instance, used for TCP socket connection in all builds except WebGL")] private int tcpPort = 8443;
[Tooltip("Name of the SmartFoxServer Zone to join")] private string zone = "BasicExamples";
// Reset buddy chat history BuddyChatHistoryManager.Init();
// Show connection lost message, in case the disconnection occurred in another scene string connLostMsg = gm.ConnectionLostMessage; if (connLostMsg != null) errorText.text = connLostMsg; }
//---------------------------------------------------------- // UI event listeners //---------------------------------------------------------- #region /** * On username input edit end, if the Enter key was pressed, connect to SmartFoxServer. */ public void OnNameInputEndEdit() { if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)) Connect(); }
/** * On Login button click, connect to SmartFoxServer. */ public void OnLoginButtonClick() { Connect(); } #endregion
// Initialize SmartFox client // The singleton class GlobalManager holds a reference to the SmartFox class instance, // so that it can be shared among all the scenes #if !UNITY_WEBGL sfs = gm.CreateSfsClient(); #else sfs = gm.CreateSfsClient(UseWebSocket.WS_BIN); #endif
private void OnConnection(BaseEvent evt) { // Check if the conenction was established or not if ((bool)evt.Params["success"]) { Debug.Log("SFS2X API version: " + sfs.Version); Debug.Log("Connection mode is: " + sfs.ConnectionMode);
sfs.InitCrypto();
// Login //sfs.Send(new LoginRequest(nameInput.text)); } else { // Show error message errorText.text = "Connection failed; is the server running at all?";
/** * Add all SmartFoxServer-related event listeners required by the scene. */ private void AddSmartFoxListeners() { sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection); sfs.AddEventListener(SFSEvent.CRYPTO_INIT, OnCryptoInit); sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost); sfs.AddEventListener(SFSEvent.LOGIN, OnLogin); sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError); }
/** * Remove all SmartFoxServer-related event listeners added by the scene. * This method is called by the parent BaseSceneController.OnDestroy method when the scene is destroyed. */ override protected void RemoveSmartFoxListeners() { // NOTE // If this scene is stopped before a connection is established, the SmartFox client instance // could still be null, causing an error when trying to remove its listeners
private void OnLoginError(BaseEvent evt) { // Disconnect // NOTE: this causes a CONNECTION_LOST event with reason "manual", which in turn removes all SFS listeners sfs.Disconnect();
// Show error message errorText.text = "Login failed due to the following error:\n" + (string)evt.Params["errorMessage"];
// Enable user interface EnableUI(true); } #endregion }
Just finished, I tried connecting using: private int tcpPort = 9933; and execute "InitCrypto". Successful connection result. So is this an SSL connection made or is it not using SSL? I really wonder. if you use port 8443, you will not be able to connect.
Is the control panel configured to open port 8443? Even though I tried opening it, I couldn't connect from the client. going to the web console with SSL still succeeds.
Port 8443 is open by default (and it looks active from the screenshots posted here) You can point your browser to https://<your-server-address>:8443 and you should see the usual welcome page with the link to the AdminTool. If you don't have a valid SSL certificate deployed you will see a browser warning saying that it could be "dangerous" to proceed.
Hi, I can access admin with ssl for port 8443. Only problem with unity client. - If I choose InitCrypto and use port 9933 tcp the connection is successful. - If not InitCrypto and using port 9933 will fail. - If use port 8443 and InitCrypto it will fail
heroumi wrote:Hi, I can access admin with ssl for port 8443. Only problem with unity client. - If I choose InitCrypto and use port 9933 tcp the connection is successful. - If not InitCrypto and using port 9933 will fail. - If use port 8443 and InitCrypto it will fail
This is correct. SmartFoxServer communicates on TCP port 9933. You don''t need to change port in order to use SSL
- If not InitCrypto and using port 9933 will fail.
Correct. Your Zone is configured to accept encrypted connections only, so non-encrypted clients won't be able to access the Zone.
- If use port 8443 and InitCrypto it will fail
Correct. Port 9933 is the used for TCP connections and communication. Port 8443 is only needed to initialize SSL cryptography.
heroumi wrote:Hi, I can access admin with ssl for port 8443. Only problem with unity client. - If I choose InitCrypto and use port 9933 tcp the connection is successful. - If not InitCrypto and using port 9933 will fail. - If use port 8443 and InitCrypto it will fail
This is correct. SmartFoxServer communicates on TCP port 9933. You don''t need to change port in order to use SSL
- If not InitCrypto and using port 9933 will fail.
Correct. Your Zone is configured to accept encrypted connections only, so non-encrypted clients won't be able to access the Zone.
- If use port 8443 and InitCrypto it will fail
Correct. Port 9933 is the used for TCP connections and communication. Port 8443 is only needed to initialize SSL cryptography.
Cheers
Thanks for your information. Very helpful. I would like to ask, Will the upcoming update of Smartfox still take place on SFS2X or will there be a new and better version?