Answer the question
In order to leave comments, you need to log in
How to connect to socket.io via phantomjs?
Hey!
Help with socket.io. I'm trying to connect to a (3rd party) socket.io server to eventually execute socket.emit . The fact is that if you try to connect to the server through the browser console, then everything goes well.
Screenshot of the process:
Since I need to do this outside of the browser, I figured it would be the right thing to use phantomjs. I am writing code like this:
// emitter.js
var io = require('./socket.io.js');
var socket = io.connect('http://static.rivalregions.com:8880');
console.log(socket.connected); // показывает false
phantom.exit(1);
phantomjs emitter.js
// emitter.js
var socket = require('socket.io-client')('http://static.rivalregions.com:8880');
socket.on('connect', function(){
console.log(socket.connected);
});
node emitter.js => true
Answer the question
In order to leave comments, you need to log in
phantomjs has been unsupported for a long time and it seems to me that socket support is not implemented there or has a bunch of bugs. Get a headless chrome ( Puppeteer ) and don't fret.
PS In general, of course, strange logic, why do you need phantomjs, if you most likely have nodejs right at hand, connect socket.io and make requests as much as you want =)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question