Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR - Detect Transport Method for a Connection on Server Side

Tags:

signalr

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

like image 432
blaster Avatar asked Mar 24 '13 19:03

blaster


2 Answers

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.

like image 193
halter73 Avatar answered Oct 24 '22 12:10

halter73


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.

like image 23
Chris Voon Avatar answered Oct 24 '22 12:10

Chris Voon