Page 4 of 4

Re: Websocket Support in 2.0

Posted: 10 Apr 2015 18:41
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?

Re: Websocket Support in 2.0

Posted: 10 Apr 2015 18:50
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)

Re: Websocket Support in 2.0

Posted: 11 Apr 2015 00:02
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)?

Re: Websocket Support in 2.0

Posted: 11 Apr 2015 18:31
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.

Re: Websocket Support in 2.0

Posted: 11 Apr 2015 23:26
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.

Re: Websocket Support in 2.0

Posted: 19 Apr 2015 18:19
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.

Re: Websocket Support in 2.0

Posted: 20 Apr 2015 04:00
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?

Re: Websocket Support in 2.0

Posted: 20 Apr 2015 13:03
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');