getting list of servers

Home Forums Syphon Syphon Development – Developer getting list of servers

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #6335
    andres
    Participant

    Hello guys, could you point me to some snippet of native code to retrive the list of all the syphon servers currently running on the system?
    Thanks!

    #6336
    bangnoise
    Keymaster

    Dead simple –

    http://syphon.v002.info/FrameworkDocumentation/#finding-servers

    or in use

    http://code.google.com/p/syphon-implementations/source/browse/trunk/Syphon%20Implementations/SyphonQC/SyphonServerListQCPlugIn.m#114

    Usually you’d want to watch for the notifications SyphonServerDirectory emits so you can continue to update the list. Note that immediately after app launch the list may be empty, as server discovery takes a small amount of time.

    #6337
    andres
    Participant

    great, thanks for the info!

    #11274
    andres
    Participant

    Hi, I opened an issue about this:

    http://code.google.com/p/syphon-implementations/issues/detail?id=26

    and did some coding. I started by adding the following native method to JSyphon:

    JNIEXPORT jobject JNICALL Java_jsyphon_JSyphonServerList_getList(JNIEnv * env, jobject jobj)
    {
    jobject serverlist = nil;

    JNF_COCOA_ENTER(env);
    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

    NSLog(@”Getting list of servers”);
    NSArray *servers = [[SyphonServerDirectory sharedDirectory] servers];
    NSMutableArray *output = [NSMutableArray arrayWithCapacity:[servers count]];
    NSLog(@”Number of servers %i”, [servers count]);

    for (NSDictionary *description in servers)
    {
    NSLog(@”Adding server = %@”, description);
    NSDictionary *simple = [NSDictionary dictionaryWithObjectsAndKeys:[description objectForKey:SyphonServerDescriptionNameKey], @”Name”, [description objectForKey:SyphonServerDescriptionAppNameKey], @”App Name”, nil];
    [output addObject:simple];
    }

    JNFTypeCoercer* coecer = [JNFDefaultCoercions defaultCoercer];
    [JNFDefaultCoercions addMapCoercionTo:coecer];

    serverlist = [coecer coerceNSObject:servers withEnv:env];

    [pool drain];
    JNF_COCOA_EXIT(env);

    return serverlist;
    }

    I can run it from Java, but gives 0 as the server count, even though I have several servers running already, which I can connect to with the Client object.

    What am I missing here? In the QC server list plugin I also see some additional initialization, in particular:

    [[SyphonServerDirectory sharedDirectory] addObserver:self forKeyPath:@”servers” options:0 context:nil];

    Do I need to do something similar, or there is it a way to query the SyphonServerDirectory only one time in order to get the list of available servers at the moment of the query?

    #11298
    bangnoise
    Keymaster

    Ah I get to type at you in two channels now 😉

    Are you doing this as soon as Syphon is loaded? It takes a moment for server discovery to happen. Otherwise the code looks good.

    #11310
    andres
    Participant

    Yes, maybe I need to add a Thread.sleep() somewhere to give some time to the server discovery?

    #11311
    bangnoise
    Keymaster

    If sleep happens on the main thread, it may block the discovery process too. Just as an experiment try doing it on a key press or somesuch, and see if you get any valid servers.

    #11343
    andres
    Participant

    I added this code to listServers():


    ArrayList tempList = null;
    int size0 = 0;
    int count = 0;
    for (int i = 0; i < 50; i++) {
    try {
    Thread.sleep(10);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    tempList = JSyphonServerList.getList();
    if (tempList.size() == size0) {
    count++;
    }
    size0 = tempList.size();
    if (10 < count) {
    break;
    }
    }

    it is not pretty, but works. However, the numbers (10ms, 50 tot attempts, etc) are basically arbitrary guesses. Also, if there are many servers, the 10 < count condition might not be enough. So I wonder if there is a better way to do this.

    #11357
    bangnoise
    Keymaster

    Assuming polling is what people are used to in Processing:

    I’d rather avoid the sleep. How about registering for SyphonServerDirectory’s notifications, and have a ServerListHasChanged() method? Users can poll that and it will return true if you’ve received a notification since they last queried it or called listServers. At that point they can call listServers().

    #11429
    andres
    Participant

    The main reference I’m using is the capture functionality in the core video library. Basically, there you just have a static Capture.list() method that returns an array of strings containing the list of available capture devices. Clearly, this is what I’m using as a model here.

    However, it seems to me that the way the server discovery works in Syphon is not conducing to this kind of approach. Correct me if I’m wrong, but what SyphonServerDirectory does is not to query the available devices at a given time, but instead it passively waits to be contacted by the servers and then adds them to its internal list of servers, right?

    An alternative polling mechanism where an event handling method would be called with the appropriate object holding the names of the registered server it is certainly possible, but the list() method would be preferred. Although the code I mentioned earlier works, it seems to me like a “problematic hack” that goes against the way server discovery works.

    #11635
    bangnoise
    Keymaster

    The list of available servers is liable to change fairly often, so providing a way to know if it has changed seems a useful thing. The most obvious scenario is when a user launches their Processing sketch and then launches a server app afterwards – you’ll have a new server appear a few seconds/mouse-clicks after launch.

    Internally, SyphonServerDirectory passively requests servers announce themselves when it loads and maintains a list locally which is returned by the servers method. As in the rest of the framework, not blocking is a feature, to avoid hung applications hanging other apps.

    Unless Processing provides a way to deliver notifications and users are accustomed to using that, having a ServerListHasChanged() (or similar) method paired with a non-blocking ServerList() method is the simplest arrangement I can think of.

    I don’t expect being able to list servers to be a much-used feature for Processing – most people will be happy to hard-code a particular server by name, or any available server if you permit that as per my comment on the serverName/appName issue on google code.

    Forgive slow responses – currently working on a show.

    Thanks for your recent activities on this – really good to see Processing support become solid.

    #11679
    andres
    Participant

    Thanks for your feedback. For the time being I will just go ahead and post a new package of the library, accompanying the 2.0b7 release of Processing and using the current list method. I will improve the server detection for the next version.

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.