Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SocketIO: Receive JSON #14625

Closed
michaelcontento opened this issue Dec 9, 2015 · 1 comment
Closed

SocketIO: Receive JSON #14625

michaelcontento opened this issue Dec 9, 2015 · 1 comment

Comments

@michaelcontento
Copy link

This issue is very similar to #14623, but can be solved independently.

Currently it's impossible for the SIODelegate to distinguish if the client has sent a plain string or a serialized (JSON) object.

As a example I'm sending this with the official JS client:

socket.emit('test-str', 'string');
socket.emit('test-obj', {type: 'obj'});

And with a delegate like:

void ServerImpl::fireEventToScript(cocos2d::network::SIOClient* _client, const std::string& event, const std::string& data)
{
    CCLOG("GOT %s %s", event.c_str(), data.c_str());
}

The log will contain:

GOT test-str "string"
GOT test-obj {"type":"obj"}

A possible solution for this could be to add another parameter to fireEventToScript indicating that data contains a serialized JSON object:

void ServerImpl::fireEventToScript(cocos2d::network::SIOClient* _client, const std::string& event, const std::string& data, const bool containsJson)
{
    if (containsJson) {
        // I know that I might use rapidjson here
    } else {
        // It's not safe to use rapidjson on data
    }
}

NOTE: As soon as we implement #14619, we should support JSON objects there too!

@michaelcontento
Copy link
Author

Closed as outdated and change no longer required

@michaelcontento michaelcontento closed this as not planned Won't fix, can't repro, duplicate, stale Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants