Comments (7)
Do you know what was the underlaying protocol for your communication - Websocke/Streaming/Polling? Also could you please make sure that the message from the client is in the format you prefer to be used on server? How do you create json messages on the client?
from sockjs-go.
I found out this is occurring because SockJS runs utils.quote on the input string, which basically JSON encodes the message again. The server should probably json.Unmarshal the message before passing it off in ReadMessage to remove this encoding.
See: https://github.com/sockjs/sockjs-client/blob/master/lib/sockjs.js#L248 and https://github.com/sockjs/sockjs-client/blob/master/lib/utils.js#L250
This is how I'm sending my message:
sock.send(JSON.stringify({
'op': 'subscribe',
'channel': 'mychannel'
}));
Which would turn into: ""{"op":"subscribe","channel":"mychannel"}""
Which would be json.Unmarshalled (in Go) to "{"op":"subscribe","channel":"mychannel"}" again
from sockjs-go.
well, you are probably right. sockjs uses a string protocol for messages and encodes each string by JSON.stringify() internally. The inverse operation should be performed on the server on each message.
I probably did a big mistake when defining ReadMessage() to return []byte. It should return "string". And then it would be clear. What you send from the client would be exactly what you get on the server.
I'll need to think about this a little more, this change would cause incompatibilities and I'm not sure how to safely introduce it at this version.
from sockjs-go.
I'm thinking maybe it could either be a config setting, or a separate Read function. This would maintain backwards compatibility.
from sockjs-go.
Feel free to send a patch/pull request if you have any.
from sockjs-go.
Sure, I'll probably create a patch when I can, probably some time this week. I found one other issue with the read format. If the sockjs-client sends 2 messages in rapid succession using xhr (haven't tested all protocols), the payload is sent as a single xhr request which is a JSON array of JSON objects:
["{\"op\":\"subscribe\",\"channel\":\"mychannel\"}","{\"op\":\"subscribe\",\"channel\":\"otherchannel\"}"]
This should probably be decoded into 2 ReadMessage() calls.
To not break old clients, I guess this should stay the same as well unless they use a new Read command or config setting. What do you think?
from sockjs-go.
fixed by #6
from sockjs-go.
Related Issues (20)
- eventsource needs to escape messages HOT 6
- RFC: Add the possibility set allowed methods on NewHandler func HOT 3
- Check if session is active HOT 1
- sockjs server not working with gorilla/websocket HOT 4
- Handler prefix does not allow grouping expressions
- .
- Do sockjs-go sessions support XDR transports? HOT 1
- Multiple prefixes always in sync? HOT 1
- CloseNotify issue. HOT 7
- add go.mod for use with vgo HOT 2
- Add context support in the socket session HOT 1
- Fix tests HOT 2
- websocket timeout HOT 2
- CORS errors when trying to connect sockjs server from a local (file://) resource HOT 6
- Issues with URL Path matching logic HOT 4
- How to use sockjs-go in a GIN project, I do not know how to send gin.Context(req, writer)) HOT 2
- CDN for sockjs-0.3.min.js is already gone. HOT 4
- Tag for v3 HOT 3
- sockjs: session not in open state HOT 3
- CheckOrigin doesn't work , how to set cors HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sockjs-go.