How to avoid Websocket OnMessage Data for timeBeing when net gets slow?

@slackmoehrle We are developing Multiplier online game, we are having problem with WebSocket when net gets slow data not getting in OnMessage method and suddenly when net gets stronger it gets all data at once, so can anyone help us with this situation, thanks in advance :slight_smile:

I’ve not used WebSocket a lot, but I know others here have. I think @smitpatel88 has?

time stamp the messages, and you can build a little logic against client time. Not sure your exact use case… but you could easily build something that will suite your needs based on server side timestamped messages

This is interesting, good idea.Time series might help keep things in-order.

Can also stamp a unit64 and ID them as well to keep true order state if you are looking at order, the timestamp was just to help with the question about lag/all at once. If client time between messages is 1/60 seconds, but server side is 2 seconds, then you know there is an issue etc.

This is very common scenario in such games and most difficult to handle as well.
Mostly we spend more time to fix such glitches after done with game-play logic.

This will help you if you are developing realtime game and its necessary.
If its turn-based games then you can use other logic as well, such as develop stack of all OnMessage responses and apply one by one.
Also try to handle all game logic at server side and just do render at client side, so such scenario wont affect you more.
You can also give listeners to ping/pong methods, from that you can easily get notified if net goes slow.

3 Likes

@smitpatel88 @tdebock thanks for the reply, yeah we are developing poker game so it’s turn-based, all logic is on server side we are passing only the object and render game according to it, we have created the stack too, so the object work according to even, now sometimes when net latency get high it won’t get response for a long time and in that period many even sent by server, and we got all event as soon latency get low and all event get at once, currently we are trying to implement ping/pong method as you suggested: slight_smile: Do know how we can unset WebSocket listener so it won’t get object onMessage, and how to implement timeout for ping-pong method with cocos2dx(CPP) it would really help us a lot, currently we are using scheduler for timeout ping-pong if you have any better suggestions let us know, thanks for help again :slight_smile:

1 Like

We are using SocketIO, so we can set listeners anytime to null.

We are using offcial SocketIO-cpp-client for this, there is inbuilt method for this. We just need to register listeners.

2 Likes

you can also flag a bool client side. bool ignoreSocketMessages = false;
The onMessage have a if (!ignoreSocketMessages) { //process message...
and you control the flag, there a few ways to ignore also just setting listener to null as @smitpatel88 recommended.

Good luck!

1 Like

thanks @smitpatel88 i have looked into it and it seems good solution we will try it into our game let here know how it goes :slight_smile: thanks again

thanks, @tdebock yeah we are using this logic right now it working and as you mentioned earlier about time stamps that are also applied with ping pong method working perfectly :slight_smile: we know if apply our own logic like this it will give us more flexibility, but we decided to try this

so it can save us a bit time, thanks for helping us out timestamps really did work :slight_smile:

@smitpatel88 one request to you, do you have any woking testing code of SocketIo the link you send with coos2dx, we have tried run that but didn’t work, it’s asking for something called boost, you guys have used it before so if you can help us out, might be demo project :slight_smile:

Yes, it depends on websocket++, boost & rapidjson. And its not easy to get it compile.
I am really sorry but i cannot share any code or any demo project due to many reasons.
You need to understand structure of each framework and need to compile one by one then add into socketio-client, and after that you can add into cocos2dx.

@smitpatel88 ohh it’s okay, well then we will try, thanks for tips :slight_smile: