Issues with WebSockets and Unicode

I am following the examples from q_for_----_Edition_22.pdf of First Derivatives for 
using WebSockets with kdb+32 v. 3.2.

  1. JSON communication setup with: .z.ws:{neg[.z.w].j.j @[value;x;{`$“'”,x}];}

when I send something like this: t:“?” 

from the browser (Chrome) I don’t get any reply back and server console has this:

q)'stack

@

k){$[10=abs t:@x;s@,/{$[x in r:“\t\n\r"\”;“\”,“tnr"\“r?x;x]}'x;99=t;”{”,..

t is getting set, but not getting the acknowledgement back from server is annoying.

Is there any other expression I could use to get around this issue?

  1. Using arraybuffer and this: .z.ws:{neg[.z.w] -8! @[value;x;{`$“'”,x}];}

things seem to be a bit faster. But setting t:“?”  I get back in the output div this:

???

So binary option seems to be unusable when Unicode is involved. It might be 

the java script deserialize function where the bug is, not sure.

Any workarounds? I prefer to be able to use option 2.

The error in #1 is generated by

q).j.j (::)

'stack

@

k){[f;x]$[1<n:“j”$.“\s”;,/f’:(n;0N)#x;f x]}[k){$[10=abs t:@x;s@,/{$[x in r:"..

so for the scenario where there is no return data, you can either ignore it or return something explicit, e.g.

.z.ws:{neg[.z.w] {$[x~(::);“ok”;x]}@[value;x;{“'”,x}];}

if you’re just sending/receiving strings, I don’t think -8! should have a performance advantage.

I want to log all requests from the network into log:([time:`datetime$()]cmd:()) table. This is what I came up with:

.z.ws:{neg[.z.w].j.j {$[x~(::);“ok”;x]} @[value;{`log insert(.z.Z;enlist x);x} x;{“'”,x}];}

I wonder how can I achieve {`log insert(.z.Z;enlist x);x} x effect with more concise code?  I am not quite sure that’s the way it should normally be done, but it works.

 

Untested code:

.z.ws:{neg[.z.w].j.j {$[x~(::);“ok”;x]}@[value;x;{“'”,x}];`log insert(.z.Z;enlist x);}


On Wednesday, December 10, 2014, Greg Borota <borota@gmail.com> wrote:

I want to log all requests from the network into log:([time:`datetime$()]cmd:()) table. This is what I came up with:

.z.ws:{neg[.z.w].j.j {$[x~(::);“ok”;x]} @[value;{`log insert(.z.Z;enlist x);x} x;{“'”,x}];}

I wonder how can I achieve {`log insert(.z.Z;enlist x);x} x effect with more concise code?  I am not quite sure that’s the way it should normally be done, but it works.

 

I does work, thanks.