最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin5PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far