blaster
blaster

Reputation: 8937

SignalR - Detect Transport Method for a Connection on Server Side

Can you discern on the server side which transport method is being used for a given SignalR connection? (WebSockets, SSE, long polling, etc.?)

Upvotes: 17

Views: 4156

Answers (2)

Chris Voon
Chris Voon

Reputation: 1999

For ASP.NET SignalR version 2.0, you can use $.connection.hub.transport.name to print out the name of the transport. It will evaluate to "serverSentEvents" and other transports.

Upvotes: 6

halter73
halter73

Reputation: 15244

Inside a Hub you can detect the transport being used by looking at the request's query string:

Context.QueryString["transport"]

This will evaluate to "webSockets", "serverSentEvents", "foreverFrame" or "longPolling".

Ideally your code should not depend on which transport is being used since SignalR abstracts that for you. However, this could be useful for logging and such.

Upvotes: 19

Related Questions