asp.net - Using SignalR to send Real Time Notification -


I want to create a new system for sending real-time business execution messages to users using SignalR. In the old system, each client connects to the trading server using the Java applet TCP connection.

I use the following tutorials as a reference

The stocktizer constructor has a line of code in the update: Share prices:

  _timer = New timer (UpdateStockProcice, Blank, _updateInterval, _updateInterval);  

However, instead of updating the stock price per 250ms, I have to update the business execution in real time. Is it OK to make a TCP connection to my trading server per customer in the consultant? It appears that in the sample code, the manufacturer of stock ticker (i.e. My trading manager) will be asked only once, but in my design, I want to make a TCP connection per client. How do I change the code to do this?

This is my code:

TradingHub.cs

  Public class TradingHub: {Private Redonly TradingManager _ Trading Manager; Public TradingHub (): This (TradingManor.Instence) {} Public TradingHebs (TradingManager Trading Manager) {_tradingManager = tradingManager; } ...}  

trading manager.cs

  public class tradingmanager {// singleton example personal redone static lazy & lt; TradingManager & gt; _instance = new Lazy & lt; TradingManager & gt; (() => New TradingManager ()); ... Public Fixed Trading Manager Instance {Return _ Instance. well; }} Public Trading Manager () {... this.apiConnector.MessageReceived + = New CustomEventHandler (this.api_MessageReceived); in this(); } Private IHubConnectionContext & lt; Dynamic & gt; Customer {Received; Set; } Private zero init () {TradingSession tradingSession = getLogin session (user); // Connect to the trading server using TCP connection. API Connector Enter connect (host, port, trading session); // Keep the message alive to the trading server from time to time _ _ timer = new timer (sendKeepAlive, null, _updateInterval, _updateInterval); } Receive Private Zero api_Message (Object Sender, CustomEventArgs E) {// When the web server receives business execution from the server, send the message immediately. Caller.SendTradeExecutionMessage (......); } GetLogin session for the public static business session (string user) {...} Private Zero sendKeepAlive {object status} {...}}  

If you create a new trading manager instead of referring to a singleton in your hub constructor, you will be creating more than one trading manager for Signal R connections. The hub is restored once per method call, every time you call a hub method or hub event (like on-connected, on reconnect, on disk connected), then your constructor will be called.

However, ONConnected is called only once on the signal R connection, however, the signal R connections are completely orthogonal for TCP connections. For example, with long polling, once a message is received, a new HTTP request is sent.

I think that every time you are connected and potentially associating it, you want to create a new tradingmanager example. The client's context.ConnectionId and save it (perhaps in concurrent extensions) so that you can get the methods of your hub using the Connection ID when calling. You can then delete the stored tradingman instances for a given connection id in the handsdirect.

You can learn more about Signal R connections:

You can learn more about Hub APIs and On * methods: < / P>


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -