سؤال

I am trying to get a simple WebSocket server going using SignalR, OWIN and Azure Worker Roles.

WorkerRole.cs:

public class WorkerRole : RoleEntryPoint
{
    public override void Run()
    {
        string url = "http://" + RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["MyEndpoint"].IPEndpoint;
        using (WebApp.Start<Startup>(url))
        {
            Trace.WriteLine(String.Format("Server running on {0}", url));
        }

        while (true) 
        {
        }
    }
    /* ... */
}

Startup.cs:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.MapSignalR();
    }
}

MyHub.cs:

public void Send(string name, string message)
{
    Clients.All.addMessage(name, message);
}

The Endpoint "MyEndpoint" is defined in the Service as http, public and private port 5001.

After starting the service, it shows up under Azure Compute Emulator as running on 5001. However, if I try to connect to ws://127.0.0.1:5001/signalr (or just ws://127.0.0.1:5001) there is no response. I am using two different web socket clients for this purpose (both are Chrome plugins and they both worked fine using other WebSocket servers).

Questions:

1) Is there anything obviously wrong with my setup?

2) Do I need to use the SignalR JS client libraries to connect to the SignalR server, or should any vanilla client implementing the WebSocket protocol be able to connect?

هل كانت مفيدة؟

المحلول

I know this is a bit of an old post but just in case someone needs it...

1) There are two problems you need to address. First of all, Start method in:

    using (WebApp.Start<Startup>(url))
    {
        Trace.WriteLine(String.Format("Server running on {0}", url));
    }

returns an IDisposable (hence the using(...){} block) means it is immediately disposed after creation since execution continues right passed Trace.Writeline(...) without pause.

It's also a bit tricky running these things under the Azure Compute Emulator for a few reasons, mainly because it remaps ports to avoid collisions. If you open up a command prompt and run

    netstat -a

you'll find that you have open ports (listening) looking something like this (in my case I'm using port 81):

    TCP    127.0.0.1:82           MyComputer:0              LISTENING
    TCP    127.0.0.3:81           MyComputer:0              LISTENING

In the general console ouput of Visual Studio, you'll also most likely see something like

    "Windows Azure Tools: Warning: Remapping private port 81 to 82 in role 'MyRoleThingy' to avoid conflict during emulation."

This all means that in order to connect to the server you're hosting using your worker role, you'll have to connect to port 82 instead of 81 (probably 5002 in your case).

2) If you implement the protocol, anything should work I think. Managing an initial connection on the port should always work.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top