SSL error on Client
Posted: 22 Jun 2024, 10:45
Hello SFS Team,
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,
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,
Code: Select all
[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";
[Tooltip("Display SmartFoxServer client debug messages")]
private bool debug = false;
//----------------------------------------------------------
// UI elements
//----------------------------------------------------------
public InputField nameInput;
public Button loginButton;
public Text errorText;
//----------------------------------------------------------
// Private properties
//----------------------------------------------------------
private SmartFox sfs;
//----------------------------------------------------------
// Unity calback methods
//----------------------------------------------------------
private void Start()
{
// Focus on username input
nameInput.Select();
nameInput.ActivateInputField();
// 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
//----------------------------------------------------------
// Helper methods
//----------------------------------------------------------
#region
/**
* Enable/disable username input interaction.
*/
private void EnableUI(bool enable)
{
nameInput.interactable = enable;
loginButton.interactable = enable;
}
/**
* Connect to SmartFoxServer.
*/
private void Connect()
{
// Disable user interface
EnableUI(false);
// Clear any previour error message
errorText.text = "";
// Set connection parameters
ConfigData cfg = new ConfigData();
cfg.Host = host;
cfg.Port = tcpPort;
cfg.Zone = zone;
cfg.Debug = debug;
#if UNITY_WEBGL
cfg.Port = httpPort;
#endif
// 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
// Configure SmartFox internal logger
sfs.Logger.EnableConsoleTrace = debug;
// Add event listeners
AddSmartFoxListeners();
// Connect to SmartFoxServer
sfs.Connect(cfg);
}
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?";
// Enable user interface
EnableUI(true);
}
}
private void OnCryptoInit(BaseEvent evt)
{
Debug.Log("Crypto initialized: " + evt.Params["success"]);
if ((bool) evt.Params["success"])
{
// Login
sfs.Send(new LoginRequest(nameInput.text));
}
}
/**
* 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);
}