<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: sockets code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 18 May 2008 09:18:12 GMT</pubDate>
    <description>DZone Snippets: sockets code</description>
    <item>
      <title>Introduction to Distributed Ruby</title>
      <link>http://snippets.dzone.com/posts/show/5233</link>
      <description>This code demonstrates a client server architecture. I executed the file simple_service.rb on my Ubuntu server (Donatello - 192.168.1.10), then from the CLI output I copied the server uri into the clipboard. I then executed the simple_client.rb on my Ubuntu desktop (Cryton - 192.168.1.3) while passing in the uri as an argument. &lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env ruby -w&lt;br /&gt;# simple_service.rb&lt;br /&gt;# A simple DRb service&lt;br /&gt;&lt;br /&gt;# load DRb&lt;br /&gt;require 'drb'&lt;br /&gt;&lt;br /&gt;# start up the DRb service&lt;br /&gt;DRb.start_service nil, []&lt;br /&gt;&lt;br /&gt;# We need the uri of the service to connect a client&lt;br /&gt;puts DRb.uri&lt;br /&gt;&lt;br /&gt;# wait for the DRb service to finish before exiting&lt;br /&gt;DRb.thread.join&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;output: druby://donatello.mydomain.com:47159&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env ruby -w&lt;br /&gt;# simple_client.rb&lt;br /&gt;# A simple DRb client&lt;br /&gt;&lt;br /&gt;require 'drb'&lt;br /&gt;&lt;br /&gt;DRb.start_service&lt;br /&gt;&lt;br /&gt;# attach to the DRb server via a URI given on the command line&lt;br /&gt;remote_array = DRbObject.new nil, ARGV.shift&lt;br /&gt;&lt;br /&gt;puts remote_array.size&lt;br /&gt;&lt;br /&gt;remote_array &lt;&lt; 1&lt;br /&gt;&lt;br /&gt;puts remote_array.size&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;from the command line&lt;br /&gt;&gt; ./simple_client.rb druby://192.168.1.10:47159&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;output:&lt;br /&gt;0&lt;br /&gt;1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Note: I substituted the domain name with the ip address because the name in question was not stored within the DNS settings.&lt;br /&gt;&lt;br /&gt;Reference: &lt;a href="http://segment7.net/projects/ruby/drb/introduction.html"&gt;Introduction to Distributed Ruby (DRb)&lt;/a&gt; [segment7.net]</description>
      <pubDate>Sat, 15 Mar 2008 00:59:13 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5233</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Getting a client's IP address with EventMachine</title>
      <link>http://snippets.dzone.com/posts/show/5098</link>
      <description>This is from, and by: &lt;a href="http://nhw.pl/wp/2007/12/07/eventmachine-how-to-get-clients-ip-address/"&gt;http://nhw.pl/wp/2007/12/07/eventmachine-how-to-get-clients-ip-address/&lt;/a&gt; .. I just wanted a more permanent reference as it's cool code.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;EventMachine::run {&lt;br /&gt;   EventMachine::open_datagram_socket $conf[:address],&lt;br /&gt;                                 $conf[:udp_port], CustomServer&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;module CustomServer&lt;br /&gt;   def receive_data d&lt;br /&gt;      pp get_peername[2,6].unpack "nC4"&lt;br /&gt;   end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 03 Feb 2008 20:12:09 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5098</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
  </channel>
</rss>
