I am trying to connect to my self-hosted SignalR server remotely using a web-based client. I can successfully connect to the server locally, but I cannot connect to the server remotely.
When I type (self-hosted ip4 address):7777/signalr/hubs in the URL of my remote browser, I see the generated hubs file. Therefore, I believe that I'm making a connection. But I want to see the web page. If you couldn't tell already, I'm a beginner to SignalR
2 more questions:
- What URL should I type into the other computer's web browser to connect to my server?
- What code determines what that URL is?
Here's my code
The self-hosted SignalR server (a wpf application)
public partial class MainWindow : Window
{
IDisposable SignalR;
private string url = "http://*:7777";
public MainWindow()
{
InitializeComponent();
SignalR = WebApp.Start(url);
Console.WriteLine("Server running on {0}", url);
}
}
Startup class
class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
app.MapSignalR();
}
}
Index Page (scripts)
@section scripts
{
<!--Reference the jQuery library. -->
<script src="~/Scripts/jquery-3.4.1.min.js"></script>
<!--Reference the SignalR library. -->
<script src="~/Scripts/jquery.signalR-2.4.3.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="http://localhost:7777/signalr/hubs"></script>
<!--Add script to update the page and send messages.-->
<script src="~/MyScripts/Main.js"></script>
}
My js file
$(function () {
$.connection.hub.url = "http://localhost:7777/signalr";
var hub = $.connection.mainHub;
$.connection.hub.logging = true;
$.connection.hub.log("Trying to connect...");
// Start connection
$.connection.hub.start()
.done(function () {
$.connection.hub.log('Now connected, connection ID=' + $.connection.hub.id);
});
})
.fail(function () {
$.connection.hub.log("Error!");
});
});