问题描述:

I would like to run a WebSocket server off a worker role in Azure.

This works fine locally on the emulator, but there is a windows firewall prompt the first time the socket server runs.

I'm wondering if anyone would know how to overcome the connection issues with regards to sockets on Azure.

My socket server implementation: OnStart

var server = new WebSocketServer("ws://theappname.cloudapp.net:8080/");

server.Start(socket =>

{

socket.OnOpen = () =>

{

Trace.WriteLine("Connected to " + socket.ConnectionInfo.ClientIpAddress,"Information");

_sockets.Add(socket);

};

});

.... etc

The client implementation:

var socket = new WebSocket("ws://theappname.cloudapp.net:8080");

socket.onopen = function () {

status.html("Connection Opened");

};

socket.onclose = function () {

status.html("Connection Closed");

}


The status changes to closed a few seconds after loading the page.


My endpoint for the worker role below:

WebSocket Input http 8080 <Not Set>


I have now tried to bind to the internal IP address using the following:

RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["WebSocket"].IPEndpoint.ToString();


SOLUTION

For the sake of anyone else facing this when implementing websockets on Azure;

  1. Your firewall probably will deny your connection if not on port 80 or 8080 so create a separate deployment for it.

  2. Endpoint must be set to TCP and not HTTP for the correct firewall rules to be created. (see image)

网友答案:

Just for the sake of trial, why don't you change your Input Endpoit from "http" to "tcp" protocol. And explicitly set the local port to 8080 (which in your case is ). Also you have to keep in mind that Windows Azure Load Balancer would kill any connection that is idleing for more than 60 seconds, so you might want to implement some kind of "ping" solution to keep the connection open.

网友答案:

You might want to take a look at this introductory video that Steve Marx (@smarx) put together on how to run node.js on Windows Azure.

相关阅读:
Top