示例#1
0
        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);
                };
            });
        }
示例#2
0
 protected virtual void OnRecieved(SocketSubscription subscription, BinaryMessage message)
 {
     Parallel.ForEach(Routes.GetMathingBinaryMessageRoutes(subscription), r => r.Handler(subscription, message));
 }