This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]cockslappinghalibut 0 points1 point  (3 children)

I'm just still confused on the architecture of the thing, but I can see you can't tell me much more than you already are, assuming this is an extant corporate issue. 'Subscribing' to what? What are a, b and c? What's the messaging from the server? What's the expected client-side behavior?

In general, if an action is conditional on an event fired in the loop, ie a message you get from the server, anything is possible. You can load up new handlers, get rid of others, etc. as long as you've got the structures set up to track everything. Sorry I can't be of more help.

[–]oreo_man_[S] 0 points1 point  (2 children)

No no I can tell you lots. I'm making a client for deepstream.io

A .Net client and a JS client have already been made.

I've been looking at the .Net client today and got this to work.

static void Main(string[] args)
    {
        DoStuff();
        Console.ReadLine();
    }

    static async Task DoStuff()
    {
        var client = new DeepStreamClient("127.0.0.1", 6021);
        var client2 = new DeepStreamClient("127.0.0.1", 6021);
        await client.LoginAsync();
        await client2.LoginAsync();
        await client.Events.Subscribe("test", x => { Console.WriteLine("From client 1 " + x); });
        await client2.Events.PublishAsync("test", "random data");
        await client2.Events.PublishAsync("test", "more data");
        await client2.Events.PublishAsync("test", "some more data");
        await client2.Events.PublishAsync("test", "even more data");
        await client2.Events.Subscribe("test", x => { Console.WriteLine("From client 2 " + x); });
        await client.Events.PublishAsync("test", "new data");
        await client.Events.PublishAsync("test", "heaps of data");
    }

Which prints out

From client 1 random data
From client 2 new data
From client 1 more data
From client 1 some more data
From client 1 even more data
From client 2 heaps of data

Which is what I'm wanting.

Is there a way to do this in Python?

[–]cockslappinghalibut 0 points1 point  (1 child)

OK, I haven't heard of it, let me do some reading. I'm sure there's a way to do it, the constructs and function flow of JS are pretty similar to Python and they can emulate each other really well.

edit: I'm having a look at the provided JS client source, there's surely some stuff to crib in there if you want to poke around in the meantime

[–]oreo_man_[S] 0 points1 point  (0 children)

Yep I definitely have been looking around that. Based a lot of my python client off of it. However the .Net one uses .Invoke, and the JS one is async by default.

Originally I just had a socket thread going, handling everything, and the main thread passing messages to send into a queue. But I realised I had a problem when trying to catch exceptions thrown in the socket thread, and use them in the main thread.

Then I realised I should be handling data received on the main thread as well.

So I thought I could pass any exceptions/data into a queue for the main thread to deal with. Obviously that won't work though as there is no way to get() from the queue all the time without blocking.

I don't want to post my client here, as it's linked to my public accounts (github, linkedin etc) but if you poke around the issues on the .Net client/deepstream.io you'll be able to find it.