I'm using PhantomJS 2.0 and trying to test socket.io between PhantomJS and NodeJS. It works but it takes alot of time for each connection (about 1000ms). I have tried on Chrome and it takes only 1-2ms. It's seems that socket.io in page.evaluate of PhantomJS is not socket.io! Here is my testing code using CasperJS:
var casper = require('casper').create({
clientScripts: ['jquery-1.11.1.min.js',["socket.io.js"]]
});
casper.start('http://localhost:8080');
casper.page.onConsoleMessage = function(msg) {
console.log(msg);
};
};
casper.then(function(){
this.evaluate(function(){
var socket = io.connect('http://localhost:8080');
socket.on('news', function (data) {
socket.emit('senddata', { time: new Date().getTime() });
});
})
})
casper.wait(5000);
casper.run();On NodeJS server I use this code:
var app = require('http').createServer(handler)
var io = require('socket.io')(app);
var fs = require('fs');
app.listen(8080);
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
io.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('senddata', function (data) {
console.log(new Date().getTime()-data.time);
});
});The result of time measuring is always >= 1000ms. I need to tranfer data in serveral ms. Can anyone help me. Thanks
var casper = require('casper').create({
clientScripts: ['jquery-1.11.1.min.js',["socket.io.js"]]
});
--
You received this message because you are subscribed to the Google Groups "phantomjs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phantomjs+...@googlegroups.com.
Visit this group at http://groups.google.com/group/phantomjs.
For more options, visit https://groups.google.com/d/optout.