I'm trying to create a simple client-server application. I came across DRuby and I try it out. Seems really nice however I'm not sure if bi-directional communication is allowed.
The functionality that I want is the following:
- The server starts running serving client with an object.
- Client connects to the server, takes object.
- Client returns it's own object to the server.
Is this No3 step possible without opening a port to the client (turning into server) ?
Regards,
You can create an interface in the server, so when the client connects to it, can change some state in the server (pass it's own object).
See this code:
server.rb
client.rb
the output is:
Also,
DRubyimplements the observer pattern, so you can make your server observable includingDRb::DRbObservablemodule in the class Server. Then you implements the methodnotifyto notify all the observers, passing objects that can be serializes (includinginclude DRb::DRbUndumped). In the client side we can add observer to the server and implement the method update to do something with the notification, see this example:server.rb
client.rb
the output is: