aberant / osc-ruby

Open Sound Control Library for Ruby
MIT License
94 stars 16 forks source link

Sharing a socket for client and server #16

Open digitalshow opened 4 years ago

digitalshow commented 4 years ago

I have the following application scheme: There is a OSC UDP server that has some properties. I connect to it and can subscribe to property changes by sending to "/xremote" periodically. The server will then send me updates on properties to the port I sent the subscription message from. So I need to receive from the same socket as I use for sending.

I use the following workaround:

@client = OSC::Client.new('10.1.2.3', 1234)
@server = OSC::EMServer.new(99999)
socket =  @client.instance_variable_get(:@so)

def @server.run(s)
  EM.error_handler{ |e|
    Thread.main.raise e
  }

  EM.run do
    EM::attach s, OSC::Connection
  end
end

It would be nice to have the possibility without a hack.

aberant commented 4 years ago

I see what you mean. I'll work through some ideas and let you know.

aberant commented 4 years ago

I'm thinking I'll go with something like your example.

@client = OSC::Client.new('10.1.2.3', 1234)
@server = OSC::EMServer.from_socket(@client.socket)
@server.run

I just need to think up a way to support the new factory methods I want that also doesn't mess up the simple EMServer initializer signature.

aberant commented 3 years ago

I'm still slowly working on this when I get free time. I'm coming up with a test harness for this and having to learn super collider so I can confidently say if my changes work or not.