I have created a dotnet core signalr project, and I want to allow other users to connect on the signalr web socket like I can do it when I connect on:
wss://echo.websocket.org
Currently, signalr generates ID when creating the negotiation, and when switching on wss it uses that id, but it is causing a problem when using external connections.
So, is it possible to tell SignalR not to generate the id when creating the websocket server, and also to accept external ws connections ?
try to use dotnet core websockets
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/websockets?view=aspnetcore-2.2
Related
I have .NET Core 2.2 + ASP.NET Core 2.2 with SignalR inside. In my development environment I have Win7 with IIS Express 10.
Unfortunately, SignalR don't use WebSockets and unfortuantely I didn't found a way to force it to do so.
On the server side, SignalR is configured like this:
app.UseSignalR(
routeBuilder => routeBuilder
.MapHub<ClientsHub>(
"/hubs/clients",
options => options.Transports = HttpTransportType.WebSockets)
);
On the client side configuration is:
this._connection = new signalR.HubConnectionBuilder()
.withUrl(this.api.getHubUrl(url), {
transport: HttpTransportType.WebSockets
})
.build();
Negotiate request from the client side of SignalR results with this answer:
{"connectionId":"1SyteS9TsDE5Q8LBRb2-VA","availableTransports":[]}
As a result, client side of SignalR writes this message to the console:
Error: Failed to start the connection: Error: Unable to initialize any of the available transports.
This obviously means that websockets are not used and SignalR can't initialize websockets.
I've found using Google that IIS Express has websockets disabled by default and I have to enable them first. I've found some setting in IISExpress/config folder in file applicationhost.config and set it to Allow (it was Deny by default):
<section name="webSocket" overrideModeDefault="Allow" />
But nothing changes.
If to disable negotiation, SignalR client tries to use WebSockets directly using url like this:
wss://localhost:44360/hubs/clients
But this request results with error code 400:
Error during WebSocket handshake: Unexpected response code: 400
Is there any possibility to force SignalR over IIS 10 to use WebSockets?
Or to force IIS 10 to allow SignalR to use WebSockets?
I am not having an answer to your question but the reasons.
Window 7 doesn't support web sockets for IIS Express. The SO answer here and here justify it.
However, if you use Kestrel web server to run your project, it will definitely use Web sockets on Window 7. I have tested the same in a project built on .NET Core 3.1 with VS 2019.
How to establish connection and send messages to remote WebSocket server from ASP.NET Core?
Is it possible now or I should wait for SignalR library to achieve this?
Sounds like you're looking for System.Net.WebSockets.Client. It's available, but not on all platforms (https://github.com/dotnet/corefx/issues/2486).
Assuming both browser & Server supports a web-socket connection.
If I've got 2 hubs on my SignalR server. and my SignalR client connects to both. does that mean that my signalR client will open up 2 separate web-socket connections to the server?
In SignalR v2+, hubs will share the same connection. I've had systems with connections to 4+ hubs without performance issue.
Question is a bit of a duplicate of: Multiple signalR connections/hubs on your website
I'm trying to implement a Server which is a Asp.Net WebApi. This server is accessed by so many child services(let it be web servers). Can SignalR be used to update these child servers so that the child servers can update all the clients attached to them?
SignalR is a Server <> Client technology, it can be used Server <> Server but its better to use a Service bus like nServicebus or MQ to pub / sub between services.
edit: If its for scalability only you can use SignalR scaleout features
I have a Web App(.NET 4.0 ASP.NET MVC3) which uses SignalR(1.0.0 alpha 2) with Hubs and Persistent Connections.
With the Hubs I use groups to send push notifications to some clients.
The problem is that when the server is accessed remotely it defaults to long pooling and only the persistent connections work. With hubs the event happens on the server but my callback is not called at the client. It works locally, though it uses SSE.
What I found is that the combination of Grouping the clients and the long pooling transport is causing the problem. I will try to debug SignalR as long as I get VS2012.
To prove this I just got this chat example modified so a hard-coded group was used and long pooling was forced - it does not work, neither on my machine (IISExpress) nor on a server (IIS 7.5). The chat works as long as you use a different transport OR do
context.Clients.All.addMessage(message);
instead of
context.Clients.Group(groupName).addMessage(message);
Here is a sample project.
Is that a bug in SignalR or I'm missing something?
Any ideas why on my deployment server SignalR would fall back to long polling on port 80 but use SSE if my site is configured on a different port?
You need to enable Auto-Rejoining groups.
Stick this in your startup code:
GlobalHost.HubPipeline.EnableAutoRejoiningGroups();