0

I've got the following config:

app.set('port', process.env.PORT || 3000); var httpserver = http.createServer(app).listen(app.get('port'), function(){ console.log('Express server listening on port ' + app.get('port')); }); var io = require('socket.io')(httpserver); app.all('/blockcallback', function(req, res){ res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "X-Requested-With"); getTxSender(req.query.tx,function(ref_wallet){ (..) }); io.emit('status', {'message': 'done'}); res.send('*ok*'); }); 

index.html

<script src="http://localhost:3000/socket.io/socket.io.js"></script> <script> var socket = io.connect('http://localhost:3000'); socket.on('status', function(datos){ alert('received'); }); </script> 

ok when i call http://localhost:3000/blockcallback looks like everything works perfectly, but i am not getting the 'status' call on the clientside.

my js console shows:

Error in event handler for extension.onRequest: undefined Stack trace: undefined localhost/:1 Error in event handler for extension.onRequest: undefined Stack trace: undefined extensions::uncaught_exception_handler:9 Stack trace: undefined extensions::uncaught_exception_handler:9 

I don't understand what's happening...

Regards,

2
  • When you do io.emit() who are you trying to send to? All connected users? Only the user making the request? Also, do you realize that the way your code is structured, neither io.emit() nor res.end("*ok*") are waiting until getTxSender() is done? Commented Oct 17, 2014 at 16:43
  • I'd say one of the first things to do here is to do further debugging on those errors in the console and eliminate all of them. Errors have a way of messing up other code, even sometimes unrelated code. Commented Oct 17, 2014 at 16:49

1 Answer 1

1

I think your problem is you haven't waited for the connection yet...

io.on('connection', function (socket) { socket.emit('status', { hello: 'world' }); }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.