Пример #1
0
        public void AddSubscription(Session session, Subscribe sub)
        {
            HashSet<Session> subs;
            if (!perUserSubs.TryGetValue(sub.User, out subs))
                subs = perUserSubs[sub.User] = new HashSet<Session>();

            lock (subs)
            {
                subs.Add(session);
            }

            List<string> list;
            if (!perSessionSubs.TryGetValue(session, out list))
                list = perSessionSubs[session] = new List<string>();

            list.Add(sub.User);
        }
Пример #2
0
        static async Task Run()
        {
            var ws = new ClientWebSocket();
            await ws.ConnectAsync(new Uri("ws://localhost:8088"), CancellationToken.None);

            var sub1 = new Subscribe() { User = "******" };
            await SendAsync(ws, sub1);

            var sub2 = new Subscribe() { User = "******" };
            await SendAsync(ws, sub2);

            var req = new GetSubscriptions();
            await SendAsync(ws, req);

            var msg = await ReceiveAsync(ws);
            var subs = (Subscriptions)msg;

            foreach (var s in subs.List)
            {
                Console.WriteLine("Sub user='******'");
            }
        }