Reputation: 8168
I am self hosting a SignalR Hubs server within my C# WinForms application:
string url = "http://localhost:8081/";
m_signalrServer = new Microsoft.AspNet.SignalR.Hosting.Self.Server(url);
// Map the default hub url (/signalr)
m_signalrServer.MapHubs();
// Start the SignalRserver
m_signalrServer.Start();
My ASP.NET web application is acting as the SignalR Hubs JavaScript client:
<script type="text/javascript" src="/Scripts/jquery.signalR-1.0.0-alpha2.min.js"></script>
<script type="text/javascript" src="http://localhost:8081/signalr/hubs"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$.connection.hub.url = 'http://localhost:8081/signalr'
var myHub = $.connection.myHub;
$.connection.hub.error(function () {
console.log("Error!");
});
$.connection.hub.start()
.done(function () {
console.log("Connected!");
})
.fail(function () { console.log("Could not connect!"); });
});
</script>
This code works properly when I am using the Server's web browser as it can access http://localhost:8081/signalr/hubs
.
However, when you browse the site externally via http://serverip
, the SignalR fails because the JQuery script is looking for a http://localhost:8081/signalr
(which I believe it looks for on your local computer).
I have changed:
$.connection.hub.url = 'http://serverip:8081/signalr'
and I enabled browsing of the website on 8081 and can browse to the website via http://serverip:8081
. However, browsing to http://serverip:8081/SignalR/Hubs
can not find the hub file that is available from http://localhost:8081/siganlr/hubs
.
Also, as a test I enabled SignalR within the ASP.NET web application via the App_Start folder -> RegisterHubs.cs file : RouteTable.Routes.MapHubs();
Doing this allows me to browse to http://serverip:8081/signalr/hubs
or http://serverip/signalr/hubs
and I can see the hubs being generated by the ASP.NET website. This is not what I want because this is not the hubs I am hosting from my C# WinForms application.
Once again, browsing to http://serverip:8081/signalr/hubs
does not find signalr or the hubs file that exists on http://localhost:8081/signalr/hubs
. Does anyone know how I can make this file available to my ASP.NET web application so that I can make SignalR work externally?
EDIT: I forgot to mention 8081 is open on the server firewall.
Upvotes: 1
Views: 3415
Reputation: 38854
Change it to:
string url = "http://*:8081/";
m_signalrServer = new Microsoft.AspNet.SignalR.Hosting.Self.Server(url);
Upvotes: 2