Websocket Support in 2.0

Discussions about RaZberry - Z-Wave board for Raspberry computer
dolpheen
Posts: 119
Joined: 10 Feb 2015 00:38

Re: Websocket Support in 2.0

Post by dolpheen »

Yes, I need to recieve info from external websocket server.
What kind of module do you mean? Can you point to some recources that I could start?
Razberry B+ 2.0.1-rc25 on ZW500 + 15 devices / Razberry B 2.0.1-rc25 on ZW300 for test
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: Websocket Support in 2.0

Post by pofs »

You have two options:
1) write websocket client in pure JS using TCP socket, but you'll have troubles handling https.
2) use some C/C++ wesocket library and wrap it into native module (there's an example published, see pinned topic)
dolpheen
Posts: 119
Joined: 10 Feb 2015 00:38

Re: Websocket Support in 2.0

Post by dolpheen »

Thank you, pofs
I found the topic viewtopic.php?f=3422&t=21409 (it's not pinned though)

Is there any additional info about sockets object except viewtopic.php?f=3424&t=20849&p=55058&hi ... ets#p55058
How can I receive info via TCP in engine (only 'send' described in your message)?
Razberry B+ 2.0.1-rc25 on ZW500 + 15 devices / Razberry B 2.0.1-rc25 on ZW300 for test
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: Websocket Support in 2.0

Post by pofs »

Strange, it was there when I looked for the last time. Think it just expired, so I pinned it back :)

There's an example of both TCP client and echo server in 2.0 developer documentation, you can pick it on github.
dolpheen
Posts: 119
Joined: 10 Feb 2015 00:38

Re: Websocket Support in 2.0

Post by dolpheen »

I used 2.0 version of developer documentation, but there is a new one 2.0.1 with additional function described.
Thank you pofs for pointing me.
So now I can use TCP connection to emit events from IR remote control.
Razberry B+ 2.0.1-rc25 on ZW500 + 15 devices / Razberry B 2.0.1-rc25 on ZW300 for test
dolpheen
Posts: 119
Joined: 10 Feb 2015 00:38

Re: Websocket Support in 2.0

Post by dolpheen »

pofs, could you help with TCP issue?
I tested sending and recieving with TCP seems OK. But onconnect(), onclose() are called only for listening sockets. For client connection there are no events fired on connection or on close, and when then I try to send on closed connection the z-way-server proccess is terminated.
Razberry B+ 2.0.1-rc25 on ZW500 + 15 devices / Razberry B 2.0.1-rc25 on ZW300 for test
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: Websocket Support in 2.0

Post by pofs »

dolpheen wrote:pofs, could you help with TCP issue?
I tested sending and recieving with TCP seems OK. But onconnect(), onclose() are called only for listening sockets. For client connection there are no events fired on connection or on close, and when then I try to send on closed connection the z-way-server proccess is terminated.
I believe onclose() should be called for connected socket as well (either if the connection is terminated by server or close() is called on the socket).
onconnect() is really called only for listening sockets, for connected you just check the status returned by connect() function. If it returns true, the connection was successful.

I'll look into crash reasons. Can you please provide some code to reproduce the issue, so it would be easier to fix it?
dolpheen
Posts: 119
Joined: 10 Feb 2015 00:38

Re: Websocket Support in 2.0

Post by dolpheen »

Thanks for pointing me, pofs. That's was my fault :oops: . I tested with simple JS and netcat and everything looks OK as you described.
The problem was that I made 'send' requests in a handler on event emit and if I reload the module without unsubscribing from this event and subscribe to a new one on next module restart there was a crash.

There is another question - if socket is closed I cannot connect to it again and have

Code: Select all

[E] [core] Callback execution error: Error: Socket is already connected
    at Error (native)
    at tcp.sock.onclose (automation/tcp-sock-test.js:10:8)
The sample code is below

Code: Select all

var sock = new sockets.tcp();

sock.onclose = function (){
  console.log('Closed!!!!!!!');
  // There we have the error that socket is already connected
  sock.connect('192.168.10.98', 8765); 
};

sock.connect('192.168.10.98', 8765);
sock.send('SEND_ONCE vixter KEY_1\n');
Razberry B+ 2.0.1-rc25 on ZW500 + 15 devices / Razberry B 2.0.1-rc25 on ZW300 for test
Post Reply