haxe cannot connect smartfox server 2x

375 views
Skip to first unread message

dương lê hoàng

unread,
Sep 25, 2016, 10:02:07 PM9/25/16
to Haxe
Hi everyone,
I'm using sfs client like: https://github.com/chapatiz/smartfox-haxe-client, but cannot connect. My project is html5 project. Can you help me, thank all

Vincent Blanchet

unread,
Sep 26, 2016, 3:35:40 AM9/26/16
to Haxe
Hi,

The client currently doesn't work with html5. You should use the official html5 api. I will update the readme to warn about it.
I will have a look in the next weeks to handle it in the haxe client.

Sorry for that.

Regards,

2016-09-26 4:02 GMT+02:00 dương lê hoàng <duong...@gmail.com>:
Hi everyone,
I'm using sfs client like: https://github.com/chapatiz/smartfox-haxe-client, but cannot connect. My project is html5 project. Can you help me, thank all

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.



--
Vincent BLANCHET,
__________________________________
Développeur,
Skype : vincent.blanchet.info

Vincent Blanchet

unread,
Sep 26, 2016, 2:00:08 PM9/26/16
to Haxe
I spend some time today to try to publish to html5 a current project. I succeded. I still haven't push the html5 branch of the haxe api to github but I will do it tomorrow morning. It's basicly some externs for the html5 api.

To use it you need to add the .js api to your project.xml like this:
<dependency path="path/to/SFS2X_API_JS.js" if="html5" />

some code must be changed in your project using compilation flags because the api function are not exactly the sames :

Here html5 api has one more parameter:
sfs.addEventListener(SFSEvent.ROOM_JOIN_ERROR, onSocketError #if html5 ,this #end);

here the connectWithConfig doesn't exist with html5
try{
#if html5
sfs.connect();
#else
sfs.connectWithConfig(config);
#end

It's not really hard to handle. I will try to add some doc about it tomorrow.

Cheers

dương lê hoàng

unread,
Sep 26, 2016, 9:47:40 PM9/26/16
to haxe...@googlegroups.com

> You received this message because you are subscribed to a topic in the Google Groups "Haxe" group.

dương lê hoàng

unread,
Sep 26, 2016, 9:49:34 PM9/26/16
to haxe...@googlegroups.com

I'm thinking must to add js library but i don't know how to do. I will try with this way. Thank you so much :D


On Sep 27, 2016 1:00 AM, "Vincent Blanchet" <vincent.bl...@gmail.com> wrote:
I spend some time today to try to publish to html5 a current project. I succeded. I still haven't push the html5 branch of the haxe api to github but I will do it tomorrow morning. It's basicly some externs for the html5 api.

To use it you need to add the .js api to your project.xml like this:
<dependency path="path/to/SFS2X_API_JS.js" if="html5" />

some code must be changed in your project using compilation flags because the api function are not exactly the sames :

Here html5 api has one more parameter:
sfs.addEventListener(SFSEvent.ROOM_JOIN_ERROR, onSocketError #if html5 ,this #end);

here the connectWithConfig doesn't exist with html5
try{
#if html5
sfs.connect();
#else
sfs.connectWithConfig(config);
#end

It's not really hard to handle. I will try to add some doc about it tomorrow.

Cheers
You received this message because you are subscribed to a topic in the Google Groups "Haxe" group.

dương lê hoàng

unread,
Sep 27, 2016, 5:05:10 AM9/27/16
to haxe...@googlegroups.com
hi Vincent,
i added .js api to project.xml
<dependency path="assets/libs/SFS2X_API_JS.js" if="html5" />
and index.html
<script type="text/javascript" src="./lib/SFS2X_API_JS.js"></script>

but i cannot create variable var smartFox:SmartFox;
can you give me tutorial link or your test project?
thank you!

2016-09-27 8:49 GMT+07:00 dương lê hoàng <duong...@gmail.com>:

I'm thinking must to add js library but i don't know how to do. I will try with this way. Thank you so much :D




--
Lê Hoàng Dương - bimkute
---------Flashdeveloper--------
skype:baby_cat_8788
phone:0982190347

Vincent Blanchet

unread,
Sep 27, 2016, 5:26:27 AM9/27/16
to Haxe
Hi,

I need to write a tuto for sure. The project I compiled yesterday is a private production project I can't share it but I will try to give you the more infos I can.

I have done some externs for html5 api, so to make it works with html( you need in your project.xml :
<haxelib name="smartfox-haxe-client" />
<dependency path="lib/SFS2X_API_JS.js" if="html5" />

then to create a connection :

#if !html5 
var config:com.smartfoxserver.v2.util.ConfigData = new com.smartfoxserver.v2.util.ConfigData();
config.httpPort = 8080;
config.useBlueBox = false;
#else
var config:com.smartfoxserver.v2.SmartFox.ConfigObj = {host:"",port:0,useSSL:false,zone:"",debug:true};
#end

config.debug = true;
config.host = 12.34.56.78 //your server ip, 127.0.0.1 for local test

config.port = #if html5 8888 #else 9933 #end; //websocket or classic socket port
config.zone = "YourZone";
#if html5
sfs = new com.smartfoxserver.v2.SmartFox(config);
#else
sfs = new com.smartfoxserver.v2.SmartFox(true);
#end
sfs.addEventListener(SFSEvent.CONNECTION, onConnection #if html5 ,this #end); //remember that the html5 api has a third parameter
sfs.addEventListener(SFSEvent.SOCKET_ERROR, onSocketError #if html5 ,this #end);
sfs.addEventListener(SFSEvent.LOGIN_ERROR, onSocketError #if html5 ,this #end);
sfs.addEventListener(SFSEvent.ROOM_CREATION_ERROR, onSocketError #if html5 ,this #end);
sfs.addEventListener(SFSEvent.ROOM_JOIN_ERROR, onSocketError #if html5 ,this #end);
try{
#if html5
sfs.connect();
#else
sfs.connectWithConfig(config);
#end

The onConnection handler :
private function onConnection(e:SFSEvent):Void 
{
#if !html5
trace("connected:" + e.params.success);
if (e.params.success)
#else
if (e.success)
#end
{
sfs.addEventListener(SFSEvent.LOGIN, onLogin #if html5 ,this #end);
sfs.send(new LoginRequest("test", "", "YourZone"));
}else{
trace("not connected");
}
}

The extension reponse handler :
private function run(e:SFSEvent):Void 
{
trace("on extension response");
var extParams:SFSObject = #if html5 e.params #else e.params.params #end;
#if html5
switch(e.cmd)
#else
switch(e.params.cmd)
#end
{

That's it. 
Hope it will help. I haven't done every externs for the api but as you can see it's easily doable. Don't hesitate to open issues on github repository and/or send me some pull requests.
I will continue to support this lib because I will use it in producction.

Cheers,

dương lê hoàng

unread,
Sep 27, 2016, 6:16:29 AM9/27/16
to haxe...@googlegroups.com
hi,
i tried follow your tut

#if !html5 
var config:com.smartfoxserver.v2.util.ConfigData = new com.smartfoxserver.v2.util.ConfigData();
config.httpPort = 6788;
config.useBlueBox = false;
#else
var config:com.smartfoxserver.v2.SmartFox.ConfigObj = {host:"sb.azgame.us",port:6788,useSSL:false,zone:"chatall",debug:true};
#end
#if html5
Browser.alert('create smartfox html5 - ');
smartFox = new com.smartfoxserver.v2.SmartFox(config);
Browser.alert('create success smartfox ');
#else
smartFox = new com.smartfoxserver.v2.SmartFox(true);
#end

but when create new, my browser run to 'create smartfox html5 - ' not show ('create success smartfox ')

Vincent Blanchet

unread,
Sep 27, 2016, 8:44:24 AM9/27/16
to Haxe
What is the error in the chrome debugger console?

2016-09-27 12:16 GMT+02:00 dương lê hoàng <duong...@gmail.com>:
hi,
i tried follow your tut

#if !html5 
var config:com.smartfoxserver.v2.util.ConfigData = new com.smartfoxserver.v2.util.ConfigData();
config.httpPort = 6788;
config.useBlueBox = false;
#else
var config:com.smartfoxserver.v2.SmartFox.ConfigObj = {host:"sb.azgame.us",port:6788,useSSL:false,zone:"chatall",debug:true};
#end
#if html5
Browser.alert('create smartfox html5 - ');
smartFox = new com.smartfoxserver.v2.SmartFox(config);
Browser.alert('create success smartfox ');
#else
smartFox = new com.smartfoxserver.v2.SmartFox(true);
#end

but when create new, my browser run to 'create smartfox html5 - ' not show ('create success smartfox ')

dương lê hoàng

unread,
Sep 27, 2016, 10:05:25 PM9/27/16
to haxe...@googlegroups.com
i using firefox browser, if i do follow smartfox-haxe-client, i can call connect  to server but server decline connect. if i follow your way or follow https://libraries.io/github/giabao/sfs2x-api, i can't create new smartfox

Vincent Blanchet

unread,
Oct 14, 2016, 12:19:09 PM10/14/16
to Haxe
It's a work in progress but you can check this sample project that I started, in order to explain how to use SmartFoxServer and haxe :

2016-09-28 4:05 GMT+02:00 dương lê hoàng <duong...@gmail.com>:
i using firefox browser, if i do follow smartfox-haxe-client, i can call connect  to server but server decline connect. if i follow your way or follow https://libraries.io/github/giabao/sfs2x-api, i can't create new smartfox

dương lê hoàng

unread,
Oct 26, 2016, 4:13:10 AM10/26/16
to haxe...@googlegroups.com
i can't find function join room, if you don't join room, you can't send extension request??? 

Vincent Blanchet

unread,
Oct 26, 2016, 7:37:12 AM10/26/16
to Haxe
You can send extension request because it is linkend to extension not to room.
The user send "play" to the server and server then create a new room if none is available or join existing one ansd start the game.
I need to spend some time this weekend to add comments 

2016-10-26 10:13 GMT+02:00 dương lê hoàng <duong...@gmail.com>:
i can't find function join room, if you don't join room, you can't send extension request??? 

dương lê hoàng

unread,
Oct 26, 2016, 10:58:04 PM10/26/16
to haxe...@googlegroups.com
i downloaded haxe client lastest, but haven't folder com.smartfoxserver.v2.extensions, how do i have file BaseClientRequestHandler

Vincent Blanchet

unread,
Oct 27, 2016, 3:43:43 AM10/27/16
to Haxe
This is server extension code so it doesn't rely to client api but to server api.
The server API is provided by these two jars mentioned in the server compilation file :

If you followed the installation notes, it must be copied from the SFS2X/lib installation repository to server/lib project folder.

2016-10-27 4:57 GMT+02:00 dương lê hoàng <duong...@gmail.com>:
i downloaded haxe client lastest, but haven't folder com.smartfoxserver.v2.extensions, how do i have file BaseClientRequestHandler

dương lê hoàng

unread,
Oct 27, 2016, 4:25:04 AM10/27/16
to haxe...@googlegroups.com
:| i coding for client, that mean i need use file SFSHandler.hx, that right? But in this file, i see after login, you call ExtensionRequest in your room but you don't join room. So how do i join exist room? 

Vincent Blanchet

unread,
Oct 27, 2016, 5:05:21 AM10/27/16
to Haxe
I think you need to read carefully the smartfox server 2x room basics on the site :

so basicly :
sfs.send( new JoinRoomRequest("The Lobby") );


I just pushed html5 extern for JoinRoomRequest. If you need some other externs check how this one was done :
then you can do a pull request and I will add it to the lib.

It's quite easy.




2016-10-27 10:25 GMT+02:00 dương lê hoàng <duong...@gmail.com>:
:| i coding for client, that mean i need use file SFSHandler.hx, that right? But in this file, i see after login, you call ExtensionRequest in your room but you don't join room. So how do i join exist room? 

dương lê hoàng

unread,
Oct 27, 2016, 5:28:59 AM10/27/16
to haxe...@googlegroups.com
if i import class JoinRoomRequest, i have error
src/com/smartfoxserver/v2/requests/BaseRequest.hx:162: characters 10-31 : Class<com.smartfoxserver.v2.entities.data.SFSObject> has no field newInstance

src/com/smartfoxserver/v2/requests/BaseRequest.hx:193: characters 19-53 : com.smartfoxserver.v2.requests.ExtensionRequest has no field useUDP

all of error at class BaseRequest.hx

Vincent Blanchet

unread,
Oct 27, 2016, 5:38:36 AM10/27/16
to Haxe
update the client lib

2016-10-27 11:28 GMT+02:00 dương lê hoàng <duong...@gmail.com>:
if i import class JoinRoomRequest, i have error
src/com/smartfoxserver/v2/requests/BaseRequest.hx:162: characters 10-31 : Class<com.smartfoxserver.v2.entities.data.SFSObject> has no field newInstance

src/com/smartfoxserver/v2/requests/BaseRequest.hx:193: characters 19-53 : com.smartfoxserver.v2.requests.ExtensionRequest has no field useUDP

all of error at class BaseRequest.hx

dương lê hoàng

unread,
Oct 27, 2016, 5:47:18 AM10/27/16
to haxe...@googlegroups.com
oh yeah, it run success, thank you so much !!!

dương lê hoàng

unread,
Oct 28, 2016, 5:38:57 AM10/28/16
to haxe...@googlegroups.com
:| i sent object to server
this is my object: var sfo:Dynamic = {cmd:Command.GET_PLAYING_INFO, un:Std.string(myData.id)};
this is object after call SFSObjectTool.instanceToSFSObject(sfo)
[Object]
p: [Object]
obj: oy3:cmdy14:getPlayingInfoy2:uny3:116g (Str)
r: 1 (Num)
c: getPlayingInfo (Str)

2016-10-27 16:47 GMT+07:00 dương lê hoàng <duong...@gmail.com>:
oh yeah, it run success, thank you so much !!!

Vincent Blanchet

unread,
Oct 28, 2016, 5:58:23 AM10/28/16
to Haxe
Yes,

It uses serialisation.
I don't see the point. You have no question in your message.

dương lê hoàng

unread,
Oct 28, 2016, 6:09:22 AM10/28/16
to haxe...@googlegroups.com
my object: var sfo:Dynamic = {cmd:getPlayingInfo, un:'116'};
after i call function  SFSObjectTool.instanceToSFSObject(sfo)
my object is change: obj: oy3:cmdy14:getPlayingInfoy2:uny3:116g (Str)

why do my object change to that?

dương lê hoàng

unread,
Oct 28, 2016, 6:25:34 AM10/28/16
to haxe...@googlegroups.com
i see function function  SFSObjectTool.sfsObjectToInstance(extParams); --> is not work.
var so = #if html5 sfsObj.obj #else sfsObj.getUtfString("obj")#end; --> (so)  always null

2016-10-28 17:09 GMT+07:00 dương lê hoàng <duong...@gmail.com>:
my object: var sfo:Dynamic = {cmd:getPlayingInfo, un:'116'};
after i call function  SFSObjectTool.instanceToSFSObject(sfo)
my object is change: obj: oy3:cmdy14:getPlayingInfoy2:uny3:116g (Str)

why do my object change to that?

Vincent Blanchet

unread,
Oct 28, 2016, 8:16:45 AM10/28/16
to Haxe
I need a context, i need more code to understand what you want to achieve.
The goal of SFSObjectTool is to easily pass haxe object between client and server if both are coded with haxe language. If not, no need of it.

dương lê hoàng

unread,
Oct 28, 2016, 9:21:47 AM10/28/16
to haxe...@googlegroups.com

Oh, server smartfox is code by java. So have you way get sfsobject from server

Vincent Blanchet

unread,
Oct 28, 2016, 10:09:41 AM10/28/16
to Haxe

2016-10-28 15:21 GMT+02:00 dương lê hoàng <duong...@gmail.com>:

Oh, server smartfox is code by java. So have you way get sfsobject from server

dương lê hoàng

unread,
Oct 28, 2016, 11:38:07 PM10/28/16
to haxe...@googlegroups.com
this is my code, i having 2 error now
1. when i call function getPlayingInfo() in clientToServer.hx --> SFSObjectTool.instanceToSFSObject(sfo) --> my object is change: obj: oy3:cmdy14:getPlayingInfoy2:uny3:116g (Str)

2. when have respone from server, if i call SFSObjectTool.sfsObjectToInstance(extParams); --> object always null

can you help me?
ClientToServer.hx

Vincent Blanchet

unread,
Oct 29, 2016, 5:17:37 AM10/29/16
to Haxe
You must not use SFSObjectTool, send your object directly :
mainData.smartFox.send(new ExtensionRequest(Command.GET_PLAYING_INFO, sfo, mainData.smartFox.lastJoinedRoom));
and the object response is in extParams.

2016-10-29 5:38 GMT+02:00 dương lê hoàng <duong...@gmail.com>:
this is my code, i having 2 error now
1. when i call function getPlayingInfo() in clientToServer.hx --> SFSObjectTool.instanceToSFSObject(sfo) --> my object is change: obj: oy3:cmdy14:getPlayingInfoy2:uny3:116g (Str)

2. when have respone from server, if i call SFSObjectTool.sfsObjectToInstance(extParams); --> object always null

can you help me?
Message has been deleted

Konstantin Djenkov

unread,
Aug 14, 2017, 7:18:53 AM8/14/17
to Haxe
Hi Everyone,

I'm trying to make the code work with the latest SFS JS API sfs2x-api-1.7.5.js but I'm having problems with this class SFSDataSerializer. I want to make the code work with the HTML native SFSObject and SFSDataSerializer not with the  Haxe Dynamic and Serializer classes. 
I've tried to add following to the code of the DefaultSFSDataSerializer class:

package com.smartfoxserver.v2.protocol.serialization;

#if html5

@:native('SFS2X.Core.DataSerializer.SFSDataSerializer')
extern class DefaultSFSDataSerializer
{
public static var instance:DefaultSFSDataSerializer;
public function object2binary(obj:SFSObject):ByteArray;
}

#else

class DefaultSFSDataSerializer implements ISFSDataSerializer
.............
.............

but when I call:

var ba:flash.utils.ByteArray = DefaultSFSDataSerializer.instance.object2binary( params );

I got the following error in the browser on this line:

var ba = SFS2X.Core.DataSerializer.SFSDataSerializer.instance.object2binary(encParams);
....
Uncaught TypeError: Cannot read property 'DataSerializer' of undefined
....


I've tried changing this @:native('SFS2X.Core.DataSerializer.SFSDataSerializer') 
to
@:native('SFS2X.DataSerializer.SFSDataSerializer')
and 
@:native('SFS2X.SFSDataSerializer')

but it seems that the compiler cannot find the class SFSDataSerializer. 

Can someone help me with this?

Regards!

Vincent Blanchet

unread,
Aug 18, 2017, 10:29:20 AM8/18/17
to Haxe
Hey,

I just had a look to the new version of the api and made a new branch for the api and the sample project :
- api : https://github.com/boorik/smartfox-haxe-client/tree/js-1.7.5
- sample : https://github.com/boorik/smartfox-haxe-fullstack/tree/js-1.7.5
Api is still not complete ( miss some externs ),but it works.
I currently don't have a lot of time to finish the externs. Current projects don't use SFS. So you can add missing externs and do a pull request.

Regarding your issue with the dataserializer, i don't see it in the doc : http://docs2x.smartfoxserver.com/api-docs/jsdoc/client/index.html
There is maybe another way to achieve this with : http://docs2x.smartfoxserver.com/api-docs/jsdoc/client/SFSObject.html#getByteArray

Hope it helps.

Regards

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.



--
Vincent BLANCHET,
__________________________________
Developer
Skype : vincent.blanchet.info

Konstantin Djenkov

unread,
Aug 19, 2017, 1:01:34 AM8/19/17
to haxe...@googlegroups.com
Hi, 

Thanks for the quick response I'll give the new version a try. 

p.s. The SFSDataSerializer is in the js code but was not exported for public access - had to change the js api to make it work.

Regards!

You received this message because you are subscribed to a topic in the Google Groups "Haxe" group.
Reply all
Reply to author
Forward
0 new messages