P
P
plutos2018-05-14 17:41:03
JavaScript
plutos, 2018-05-14 17:41:03

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:
YTkiV.png
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);

Then I execute a command in Linux but false
phantomjs emitter.js
is returned Why is this happening? How to do it right? SOLUTION: Thanks to user Michael
// 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

1 answer(s)
M
Michael, 2018-05-14
@plutos

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 question

Ask a Question

731 491 924 answers to any question