<?xml version="1.0" encoding="UTF-8"?>
<wiki>
  <body>&lt;p&gt;When I started making Legs, I was making my dream networking library. The thing I wish had existed back when I was first messing with computers. For this reason, Legs is extremely simple, and tries to ignore some of the complicated aspects of how the internet works.&lt;/p&gt;
&lt;p style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://img.skitch.com/20080717-jsr673ajfnq76ixy5cg68222eu.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Networking on the internet works a bit like telephones. Each internet connection has a number (IP Address) which looks like four digits, separated by periods, or in really modern systems, has even more numbers, some letters, and are separated by colons instead (you&amp;#8217;ll be seeing more and more of that as the years go by). You can use that number to connect to the computer or router attached to that internet connection. As well as that, so that you can have multiple connections going at the same time, we have &amp;#8216;port numbers&amp;#8217;, which can be anything between 1 and something like 64,000. Websites run on Port 80 usually, so that&amp;#8217;s the port your web browser uses to talk to the web server if you don&amp;#8217;t specify a port number in the &lt;span class=&quot;caps&quot;&gt;URL&lt;/span&gt;. Legs usually runs on 30274. It&amp;#8217;s just a really big number I made up. If you&amp;#8217;re going to use a different number (which you&amp;#8217;ll need to, if you want to run multiple different programs using legs on the same computer) it&amp;#8217;s a good idea to make it bigger than 1,500, and to search for &amp;#8216;Port Whatever-Number&amp;#8217; on the web to see if any other programs are already using it.&lt;/p&gt;
&lt;p&gt;Messages pass through the internet as strings of binary or text. Making up your own format and then writing all this code to parse it and figure out all it&amp;#8217;s meaning when it gets to the other end is tedious and dull, so instead of that we&amp;#8217;re going to use the simple system of classes. You should already know how to make your own class with methods in it, and how to make an &lt;i&gt;instance&lt;/i&gt; of that class and run those methods. Basic stuff, seriously. If you don&amp;#8217;t yet know about this, I suggest &lt;a href=&quot;http://poignantguide.net/ruby/&quot;&gt;Why&amp;#8217;s Poignant Guide&lt;/a&gt; to get you started hacking with ruby. :)&lt;/p&gt;
&lt;p&gt;Legs will be just like that. You put a bunch of methods in to Legs, then you create an instance of Legs and run the method! Easy as pie. Here&amp;#8217;s how:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
require 'legs'

Legs.start do
  def echo(thing)
    &quot;You asked me to tell you #{thing}&quot;
  end
end

sleep
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The sleep at the end tell&amp;#8217;s ruby &#8220;Just because you got to the end doesn&amp;#8217;t mean we&amp;#8217;re done! Have a sleep, and I&amp;#8217;ll wake you up when I need you again&#8221;. Without that bit, ruby would just close instantly after. The important stuff is the stuff above that though! It&amp;#8217;s like a class except that first line. Now, in another ruby program we can do this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
require 'legs'

remote_stuff = Legs.new
puts remote_stuff.echo(&quot;that ponies are clearly better pets than dogs and cats and every kid should have one!&quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, if we run the first script with the Legs.start part and just leave that open, then in another Terminal window run the second script, you&amp;#8217;ll see it talk to the first one and work together to find the answer! Pretty nifty, eh?&lt;/p&gt;
&lt;p&gt;Now suppose the first script is running on another computer on your network. Now, on your main computer, change the script so that middle line goes like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
remote_stuff = Legs.new('123.123.123.123')
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But put that number you found in there instead at the end. Run the script, and it should work just the same, but now it&amp;#8217;s over multiple computers! You can also put a &lt;i&gt;hostname&lt;/i&gt; in there like &amp;#8216;google.com&amp;#8217;, but that won&amp;#8217;t work because google is legless. It&amp;#8217;s just a good thing to know because if you want to show your app to friends over the internet you can use something called a &amp;#8216;Dynamic &lt;span class=&quot;caps&quot;&gt;DNS&lt;/span&gt;&amp;#8217; to get a hostname you can put in the program instead of a bunch of numbers. Those things are good because home internet connections sometimes change to a new IP address, and the Dynamic &lt;span class=&quot;caps&quot;&gt;DNS&lt;/span&gt; address will stay the same but you can update it to your new IP address if it changes. :)&lt;/p&gt;
&lt;p&gt;So that&amp;#8217;s the basics of Legs! There&amp;#8217;s a fair bit more to be had, and I&amp;#8217;ll try to write some articles on those bits soon!&lt;/p&gt;</body>
  <created-at type="datetime">2008-07-17T02:21:16-07:00</created-at>
  <id type="integer">37043</id>
  <permalink>baby-steps</permalink>
  <repository-id type="integer">31406</repository-id>
  <title>Baby Steps</title>
  <updated-at type="datetime">2008-07-17T02:31:17-07:00</updated-at>
  <user-id type="integer">12768</user-id>
</wiki>
