protected void OnBootstrap() { InternalSocketServer.Start(connection => { connection.OnOpen = () => OnSubscribe(connection); connection.OnClose = () => OnDesubscribe(connection); connection.OnMessage = message => { var subscription = GetSubscription(connection); var textMessage = SerializerFor<TextMessage>.Deserialize(message); textMessage.SubscriptionId = subscription.SubscriptionId; OnRecieved(subscription, textMessage); }; connection.OnBinary = message => { var subscription = GetSubscription(connection); var binaryMessage = new BinaryMessage { Data = message, SubscriptionId = subscription.SubscriptionId }; OnRecieved(subscription, binaryMessage); }; }); }
protected virtual void OnRecieved(SocketSubscription subscription, BinaryMessage message) { Parallel.ForEach(Routes.GetMathingBinaryMessageRoutes(subscription), r => r.Handler(subscription, message)); }