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

Binary data transfert #13

Open
mmardinian opened this issue Nov 26, 2018 · 2 comments
Open

Binary data transfert #13

mmardinian opened this issue Nov 26, 2018 · 2 comments

Comments

@mmardinian
Copy link

Hi,

I try to transfert binary buffer to a Nats client using nats-websocket-gw and websocket-nats.
But binary data don't seems to be handled well.
I get some "EOF" messages which seems to be related to a string format.

Could you tell me how to configure the connection beween websocket-nats and nats-websocket-gw in binary please?

Thanks.
Michael

@InfernoZeus
Copy link

@mmardinian Not sure if you're still interested, but I'm adding this just as much for other's who might have the same problem.

I couldn't get this working without some changes. The following patch to dist/websocket-nats.js let me receive the binary buffer when setting the encoding to buffer:

$ diff websocket-nats.js.orig websocket-nats.js
863a864
> 		client.payload.data = mbuf.slice(0, client.payload.size);
865a867
> 		client.payload.data = client.inbound.slice(0, client.payload.size);
936,941c938,947
< 	      var msg = this.payload.msg;
< 	      if (this.options.json) {
< 	        try {
< 	          msg = JSON.parse(new Buffer(this.payload.msg, this.options.encoding).toString());
< 	        } catch (e) {
< 	          msg = e;
---
> 	      if (this.options.encoding == 'binary') {
> 	        var msg = this.payload.data;
> 	      } else {
> 	        var msg = this.payload.msg;
> 	        if (this.options.json) {
> 	          try {
> 	            msg = JSON.parse(new Buffer(this.payload.msg, this.options.encoding).toString());
> 	          } catch (e) {
> 	            msg = e;
> 	          }

I haven't managed to test it with multi-chunk payloads though. (I don't know when that occurs, so difficult to trigger...)

@happy-python
Copy link

Hi, binary support is ok?

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

3 participants