how i can send String array to client unity

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

Moderators: Lapo, Bax

qazokmijn01
Posts: 1
Joined: 15 May 2018, 08:34

how i can send String array to client unity

Postby qazokmijn01 » 15 May 2018, 08:40

i try used on server smarfox
Collection<String> name=new ArrayList<String>();
name.add("a");name.add("b");
sfsobject.putUtfStringArray("name",name)

but client unity
string[] name1 = dt.GetUtfStringArray("name");
print name i got a empty array name1 // []

sorry my english not good pls help me ! tkanks you
User avatar
Bax
Site Admin
Posts: 4385
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: how i can send String array to client unity

Postby Bax » 16 May 2018, 14:33

We tested this and everything works as expected.

Server Extension:

Code: Select all

ISFSObject dataObj = new SFSObject();
Collection<String> name = new ArrayList<String>();
name.add("a");
name.add("b");
      
dataObj.putUtfStringArray("name", name);
      
send("test", dataObj, sender);


Unity client, in the Extension Response listener:
(tested in the Editor for both standalone platform and webgl platform)

Code: Select all

ISFSObject para = (ISFSObject) evt.Params["params"];
Debug.Log(para.GetUtfStringArray("name")[0]);
Debug.Log(para.GetUtfStringArray("name")[1]);


Output:

Code: Select all

a
UnityEngine.Debug:Log(Object)
MainController:OnExtensionResponse(BaseEvent) (at Assets/Scripts/MainController.cs:298)
Sfs2X.Core.EventDispatcher:DispatchEvent(BaseEvent)
Sfs2X.SmartFox:ProcessEvents()
MainController:Update() (at Assets/Scripts/MainController.cs:41)

b
UnityEngine.Debug:Log(Object)
MainController:OnExtensionResponse(BaseEvent) (at Assets/Scripts/MainController.cs:299)
Sfs2X.Core.EventDispatcher:DispatchEvent(BaseEvent)
Sfs2X.SmartFox:ProcessEvents()
MainController:Update() (at Assets/Scripts/MainController.cs:41)


Please make sure you are using the latest version of the C# API (currently v1.7.6).
Paolo Bax
The SmartFoxServer Team

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 2 guests