input-output-hk / cardano-sl

Cryptographic currency implementing Ouroboros PoS protocol
Apache License 2.0
3.77k stars 629 forks source link

Web socket events do not work. #3006

Open rahilzebpay opened 6 years ago

rahilzebpay commented 6 years ago

Hello,

I have been trying to work with explorer events referring to the documentation https://cardanodocs.com/technical/explorer/ but not able to get it to work.

My main goal is to listen to new block events, so I can process those blocks.

var client = require('socket.io-client');
var socket = client('http://localhost:8100'); //also tried on port 8110
socket.on('SubBlockLastPage', function(msg){ console.log(msg); });

Now I'm expecting the callback to be triggered every time the last page changes (new slot added). But nothing happens. I have the explorer running along with the node.

Is there something I'm missing?

vsubhuman commented 6 years ago

There's a unicode problem in explorer, thanks to @ilap

https://forum.cardano.org/t/how-to-query-based-on-block-height-and-listen-to-new-block-transaction-events-also-sockets-api/12472/10

quannd-ibl commented 6 years ago

hi cardano team I hope you fix this issue, and support socket in node js

johnalotoski commented 6 years ago

I've been able to get socket.io to work with a local Cardano-SL explorer node to port 8110 and also direct to the cardanoexplorer.com website. The former sets up a websocket, the latter uses XHR polling, both via the socket.io-client library in the testing I've tried.

Here's a sample HTML file with embedded JS and a couple screenshots.

https://gist.github.com/johnalotoski/550dc50a9417813be52b606954fb30a0

sockets-ws-localhost

sockets-xhr-explorer-prod

John

ilap commented 6 years ago

Checked with cardanoexplorer.com using polling transport with a local HTTP server listening on localhost:3100. Cool thx.

johnalotoski commented 6 years ago

Welcome! Happy to help!

datnv-ibl commented 5 years ago

Please fix this issue for socket.io on nodejs. Thank

ilap commented 5 years ago

Please fix this issue for socket.io on nodejs. Thank

What's the problem? It's working in some conditions. See @johnalotoski's comments above

datnv-ibl commented 5 years ago

Yes, It work with chrome, but Nodejs won't work.

Nodejs Client

datnv@lt29-datnv:~/projects/ibl-master-socket$ npm start
> ibl-wallet-socket@0.1.0 start /home/datnv/projects/ibl-master-socket
> NODE_ENV=dev node index.js

2018-09-26 09:14:54.391 ERROR 14543 SOCKET ADA Socket connect error: http://172*****.92:8110 - websocket error
2018-09-26 09:14:55.924 ERROR 14543 SOCKET ADA Socket connect error: http://172*****.92:8110 - websocket error
2018-09-26 09:14:57.137 ERROR 14543 SOCKET ADA Socket connect error: http://172*****.92:8110 - websocket error

Cardano

3|connect-mainnet-explorer  | [cardano-sl.node.notifier.socket-io:Debug:ThreadId 190423] [2018-09-26 02:14:54.38 UTC] New session has started (#"BzMAJw45BTM8MDojFgQK")
3|connect-mainnet-explorer  | [cardano-sl.node.notifier.socket-io:Debug:ThreadId 190429] [2018-09-26 02:14:55.92 UTC] New session has started (#"DRINDSQmBDQVLAUuLzUE")
unluckythoughts commented 5 years ago

I too am experiencing the same issue on NodeJS (printing the received data) with the socket.io client branch release/1.3.0,

    �0{"pingInterval":25000,"pingTimeout":60000,"upgrades":["websocket"],"sid":"Jw4iCjIyOSs/OxQSLQsr"}
{ Error: server error
    at Socket.onPacket (/XXXXXXXXXXXXXXXXX/test/node_modules/engine.io-client/lib/socket.js:450:19)
    at XHR.<anonymous> (/XXXXXXXXXXXXXXXXX/test/node_modules/engine.io-client/lib/socket.js:273:10)
    at XHR.Emitter.emit (/XXXXXXXXXXXXXXXXX/test/node_modules/component-emitter/index.js:133:20)
    at XHR.Transport.onPacket (/XXXXXXXXXXXXXXXXX/test/node_modules/engine.io-client/lib/transport.js:145:8)
    at callback (/XXXXXXXXXXXXXXXXX/test/node_modules/engine.io-client/lib/transports/polling.js:144:10)
    at Object.exports.decodePayload (/XXXXXXXXXXXXXXXXX/test/node_modules/engine.io-parser/lib/index.js:295:14)
    at XHR.Polling.onData (/XXXXXXXXXXXXXXXXX/test/node_modules/engine.io-client/lib/transports/polling.js:148:10)
    at Request.<anonymous> (/XXXXXXXXXXXXXXXXX/test/node_modules/engine.io-client/lib/transports/polling-xhr.js:126:10)
    at Request.Emitter.emit (/XXXXXXXXXXXXXXXXX/test/node_modules/component-emitter/index.js:133:20)
    at Request.onData (/XXXXXXXXXXXXXXXXX/test/node_modules/engine.io-client/lib/transports/polling-xhr.js:299:8) code: 'parser error' }
Yoge-Code commented 5 years ago

It works with python-socketio Here is the demo I tried.

import socketio

sio = socketio.Client()

@sio.on('connect')
def on_connect():
    print('connection established')
    sio.emit('CallMe')
    sio.emit('Subscribe SubBlockLastPage')

@sio.on('CallYou')
def on_message(*args):
    print args
    print('Call')

@sio.on('BlocksLastPageUpdated')
def on_block(*args):
    print args
    print('block')

@sio.on('disconnect')
def on_disconnect():
    print('disconnected from server')

url = "http://localhost:8110"
sio.connect(url)
sio.wait()