Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XMLHttpRequest: Network Error 0x2efd, Could not complete the operation due to error 00002efd

I am using socket.io for a windows azure project. Strangely the socket.io server starts when i just deploy the web role but when i deploy the whole cloud project, the socket.io server doesnt start and i get this error -

"SCRIPT7002: XMLHttpRequest: Network Error 0x2efd, Could not complete the operation due to error 00002efd."

I have absolutely no idea what that means. Can anyone help me out on this one? I have been banging my head about it all day.

SocketClient.html

<script>
var socket = io.connect('http://127.0.0.1:4001');
socket.on('news', function (data) {
    console.log(data);       
});

$(function () {
    $("#sendresponse").bind("click", function () {
     socket.emit('server', 'Hello World');

    });
}
);
</script>

App.js

var app = require('express')(), server = require('http').createServer(app), io = require('socket.io').listen(server);

server.listen(4001);

app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});

io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'first time connect' });
socket.on('server', function (data) {
    console.log(data);
    socket.emit('news',"hello");
});
});
like image 873
Bitsian Avatar asked Mar 05 '13 12:03

Bitsian


1 Answers

Turned out that the App.js script was not running when i deployed the cloud project, i.e the iisnode handler which i had put in my web.config wasnt doing its job when the whole cloud project was deployed. After going through this article i found out that i had to put some files in my bin folder of web role namely - ChangeConfig.ps1,download.ps1,node.cmd,setup_web.cmd. you can generate these files when you go through that article. And finally you have to put this code in your ServiceDefinition.csdef

<Startup>      
 <Task commandLine="setup_web.cmd &gt; log.txt" executionContext="elevated">
    <Environment>
      <Variable name="EMULATED">
        <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
      </Variable>
      <Variable name="RUNTIMEID" value="node;iisnode" />
      <Variable name="RUNTIMEURL" value="" />
    </Environment>
  </Task>
</Startup>

And voila!! It works like a charm. You would still have to start the socket.io server by running 127.0.0.1/App.js on browser. I am still looking at how to start App.js programattically.

like image 82
Bitsian Avatar answered Nov 04 '22 00:11

Bitsian