How to send data back

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

tulparid
Posts: 8
Joined: 01 Jan 2021, 08:56

How to send data back

Postby tulparid » 07 Jan 2021, 10:15

I have received LOGIN_IN_DATA but how can i send back LOGIN_OUT_DATA. I am working on a server emulator for CPI.

Thanks
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to send data back

Postby Lapo » 07 Jan 2021, 15:06

Hi,
the LOGIN_OUT_DATA object is passed in the SFSEvent.USER_LOGIN event.

Check the docs here:
http://docs2x.smartfoxserver.com/Extens ... -assistant
Section #4, specifically.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
tulparid
Posts: 8
Joined: 01 Jan 2021, 08:56

Re: How to send data back

Postby tulparid » 07 Jan 2021, 16:38

Lapo wrote:Hi,
the LOGIN_OUT_DATA object is passed in the SFSEvent.USER_LOGIN event.

Check the docs here:
http://docs2x.smartfoxserver.com/Extens ... -assistant
Section #4, specifically.

Cheers


i know but how can i send data back with LOGIN_OUT_DATA using LOGIN_IN_DATA data

Thanks
Luke64
Posts: 21
Joined: 08 Nov 2020, 23:15

Re: How to send data back

Postby Luke64 » 12 Jan 2021, 15:59

tulparid wrote:i know but how can i send data back with LOGIN_OUT_DATA using LOGIN_IN_DATA data

Just get the SFSObject from the event and add to it. Everything you add will be returned.

Here's an example from my code:

Code: Select all

        // get SFSObject provided to return a new name to the client after login
        ISFSObject outData = (ISFSObject) event.getParameter(SFSEventParam.LOGIN_OUT_DATA);
        outData.putUtfString(SFSConstants.NEW_LOGIN_NAME, username);
        outData.putByteArray(PARAM_KEY_PROTOBUF, responsePb);


hth
tulparid
Posts: 8
Joined: 01 Jan 2021, 08:56

Re: How to send data back

Postby tulparid » 14 Jan 2021, 23:04

Luke64 wrote:
tulparid wrote:i know but how can i send data back with LOGIN_OUT_DATA using LOGIN_IN_DATA data

Just get the SFSObject from the event and add to it. Everything you add will be returned.

Here's an example from my code:

Code: Select all

        // get SFSObject provided to return a new name to the client after login
        ISFSObject outData = (ISFSObject) event.getParameter(SFSEventParam.LOGIN_OUT_DATA);
        outData.putUtfString(SFSConstants.NEW_LOGIN_NAME, username);
        outData.putByteArray(PARAM_KEY_PROTOBUF, responsePb);


hth


well i tried this but looks like it didn't really work.

Code: Select all

 
 
 String login_in_data_json = "{stringified json of login in data here}";
 
  byte[] bytes = login_in_data_json.getBytes();
        
 ISFSObject outData = (ISFSObject) event.getParameter(SFSEventParam.LOGIN_OUT_DATA);
 outData.putUtfString(SFSConstants.NEW_LOGIN_NAME, name);
 outData.putByteArray("outData", bytes);
 
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to send data back

Postby Lapo » 15 Jan 2021, 07:55

Why are you saying it didn't work?
Do you have an error? If so post the details, please.

Are trying to read the received data correctly?
On the client side you need to do something like this:

Code: Select all

public void OnLoginData(BaseEvent evt)
{
   ISFSObject sfso = (ISFSObject) evt.Params["data"];
   sfso.getByteArray("outData");
        ...
}

This is C#, if you're using a different platform let me know.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
tulparid
Posts: 8
Joined: 01 Jan 2021, 08:56

Re: How to send data back

Postby tulparid » 15 Jan 2021, 16:28

Lapo wrote:Why are you saying it didn't work?
Do you have an error? If so post the details, please.

Are trying to read the received data correctly?
On the client side you need to do something like this:

Code: Select all

public void OnLoginData(BaseEvent evt)
{
   ISFSObject sfso = (ISFSObject) evt.Params["data"];
   sfso.getByteArray("outData");
        ...
}

This is C#, if you're using a different platform let me know.

Cheers


I don't have any error, I am trying to write received data back using LOGIN_OUT_DATA
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to send data back

Postby Lapo » 16 Jan 2021, 08:41

Please show the server side code used to send the data and the relative client side handler that reads the data in the login handler.
Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 37 guests