最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Websocket server on Azure with node.js - Stack Overflow

programmeradmin1浏览0评论

I'm trying to create a websocket server with Node.js to run on a Windows Azure. This should be simple, but I have run into problems I haven't been able to find solutions for anywhere.

This is my serverside code:

var ws = require('websocket.io')
    , http = require('http').createServer().listen(process.env.PORT)
    , server = ws.attach(http)

server.on('connection', function (socket) {
    socket.on('message', function () { });
    socket.on('close', function () { });
});

How do I know which port I need to connect to? My client code is:

var ws = new WebSocket("ws://socketiopuge.azurewebsites");

ws.onopen = function () {
    alert("opened");
};

ws.onmessage = function(msg) {
    alert(msg);
};

ws.onclose = function () {
    alert("closed");
};

When I run the code I get an 501 error code, and the onclode event is fired. I believe the problem is that I need to specify a port number when I create the WebSocket. Can any of you point me in the right direction? Thanks!

I'm trying to create a websocket server with Node.js to run on a Windows Azure. This should be simple, but I have run into problems I haven't been able to find solutions for anywhere.

This is my serverside code:

var ws = require('websocket.io')
    , http = require('http').createServer().listen(process.env.PORT)
    , server = ws.attach(http)

server.on('connection', function (socket) {
    socket.on('message', function () { });
    socket.on('close', function () { });
});

How do I know which port I need to connect to? My client code is:

var ws = new WebSocket("ws://socketiopuge.azurewebsites");

ws.onopen = function () {
    alert("opened");
};

ws.onmessage = function(msg) {
    alert(msg);
};

ws.onclose = function () {
    alert("closed");
};

When I run the code I get an 501 error code, and the onclode event is fired. I believe the problem is that I need to specify a port number when I create the WebSocket. Can any of you point me in the right direction? Thanks!

Share Improve this question asked Jun 14, 2012 at 21:57 JPugeJPuge 5961 gold badge5 silver badges14 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

About your question "How do I know which port I need to connect to", you would need to create an Input Endpoint and set proper PORT for it. Once you configured it, you will be using the same port in your code to bind and use.

Here is an example about Running socket.io on Windows Azure Web and Worker roles

If you host socket.io in a Windows Azure Web Role, please disable the WebSockets transport on the server because Windows Azure Web role runs on IIS7, web sockets are not supported on IIS7 yet. With Worker Role you dont need to worry about it and you can directly use Web Sockets.

If you're using the new Azure web sites, they do not support websockets yet. The same goes for all web sites hosted through IIS - node.js or not.

Your only way of currently supporting websockets in Azure is by using worker roles and supplying your own node.js executable.

发布评论

评论列表(0)

  1. 暂无评论