Problem with connecting to server using different users Unity-Smartfoxserver

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

Moderators: Lapo, Bax

rizarefaldi
Posts: 1
Joined: 11 Jun 2021, 17:03

Problem with connecting to server using different users Unity-Smartfoxserver

Postby rizarefaldi » 11 Jun 2021, 17:16

I am making a simple memory game. I have already made the game work with smartfoxserver. But when I tried to build another machine and let them run simultaneously, one player would be log out when another log in. Could you guys help me with this one. Here is the code on the client. Also is once the game start is there any way for the two machine to connect to eachother. For example showing the score from Player1 to Player2.

Code: Select all

using Sfs2X;
using Sfs2X.Core;
using Sfs2X.Entities.Data;
using Sfs2X.Requests;
using Sfs2X.Util;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices.ComTypes;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using Sfs2X.Requests.MMO;
 public class GameController : MonoBehaviour
{
public string defaultHost = "127.0.0.1";
public int defaultTcpport = 8888;
public int defaultWsport = 8080;
public string Zonename = "BasicExamples";
public string Username = "guest";
public string Roomname = "The Lobby";

private SmartFox sfs;

void Awake()
{
    SourceSprites = Resources.LoadAll<Sprite>("Sprite/GameImages");
}
void Start()
{
    Login_Click();
    TotalGuess = btnlist.Count / 2;
    GetButton();
    AddListener();
    AddSprites();
    shuffle(GameSprite);
   }
 public void Login_Click()
   {
    if (sfs == null || !sfs.IsConnected)
    {
        sfs = new SmartFox();
        sfs.ThreadSafeMode = true;
        sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
        sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
        sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
        sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
        sfs.AddEventListener(SFSEvent.ROOM_JOIN, OnJoinRoom);
        sfs.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnJoinRoomError);
        sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, GetResult);


        ConfigData cfg = new ConfigData();
        cfg.Host = defaultHost;
        cfg.Port = defaultTcpport;
        cfg.Zone = "BasicExamples";
        cfg.Debug = true;
        Debug.LogError("defaultHost " + defaultHost);
        Debug.LogError("defaultTcpport " + defaultTcpport);
        sfs.Connect(cfg);
    }
}
void OnLogin(BaseEvent evt)
{
    Debug.Log("Login Success");
    sfs.Send(new JoinRoomRequest("The Lobby"));
}
  void OnJoinRoom(BaseEvent evt)
{

    Debug.Log("Joined Room"+ evt.Params["room"]);
}
void OnJoinRoomError(BaseEvent evt)
{
    Debug.Log("Join Room Error" + evt.Params["errorMessage"]);
}
void OnLoginError(BaseEvent evt)
{
    Debug.Log("Login Error"+ evt.Params["errorMessage"]);
}
void OnConnection(BaseEvent evt)
{
    if ((bool)evt.Params["success"])
    {
        Debug.Log("Connection Success");
        sfs.Send(new LoginRequest(Username, "", Zonename));
    }
    else
    {
        Debug.Log("Connection Error");
    }
}
void OnConnectionLost(BaseEvent evt)
{

}
Regards
rizarefaldi ukuran a4
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Problem with connecting to server using different users Unity-Smartfoxserver

Postby Lapo » 12 Jun 2021, 10:50

Hi,
one reason for this (one user being kicked out when another is logged in) is that both users are trying to log in with the same exact user name. With SFS2X each user must have a unique name, otherwise it will be recognized as the same client and only one session can exist for the same player at the same time.

Make sure to use two different names.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 35 guests