<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -0,0 +1,125 @@
+#!/usr/bin/ruby
+
+# This file is part of ScopePort (Client Ruby).
+#
+# Copyright 2009 Lennart Koopmann
+#
+# ScopePort (Client Ruby) is free software: you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# ScopePort (Client Ruby) is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ScopePort (Client Ruby).  If not, see &lt;http://www.gnu.org/licenses/&gt;.
+
+hostname = &quot;localhost&quot;
+port = 12200
+host_id = 1
+password = &quot;secret&quot;
+
+require &quot;socket&quot;
+
+class Conversation
+  private
+  def socket
+    @socket
+  end
+
+  public
+  def initialize hostname, port
+    raise &quot;Invalid port&quot; if port &lt; 0 or port &gt; 65535
+    @hostname = hostname
+    @port = port
+  
+    # Try to open a socket.
+    begin
+      @socket = TCPSocket.open(@hostname, @port)
+      # Check the answer.
+      msg = @socket.recvfrom 100
+      raise &quot;Empty or no reply&quot; if msg[0].length == 0
+      raise msg[0] if msg[0] != &quot;Okay&quot;
+    rescue =&gt; e
+      raise e
+    end
+  end
+
+  def close
+    begin
+      @socket.close
+    rescue =&gt; e
+      raise e
+    end
+  end
+
+  def login host_id, password
+    begin
+      login_message = &quot;#{host_id},login,#{password}&quot;
+      @socket.send login_message, login_message.length
+      msg = @socket.recvfrom 100
+      raise &quot;Empty or no reply&quot; if msg[0].length == 0
+      raise msg[0] if msg[0] != &quot;Okay&quot;
+    rescue =&gt; e
+      raise e
+    end
+  end
+
+  def send_sensor_data(host_id, sensor, value)
+    raise &quot;Missing host_id&quot; if !host_id.integer?
+    raise &quot;Missing sensor name&quot; if sensor.length &lt;= 0
+    raise &quot;Missing sensor value&quot; if value.length &lt;= 0
+    raise &quot;Illegal characters&quot; if sensor.include? &quot;,&quot; or value.include? &quot;,&quot;
+
+    begin
+      sensor_message = &quot;#{host_id},#{sensor},#{value}&quot;
+      @socket.send sensor_message, sensor_message.length
+      msg = @socket.recvfrom 100
+      raise &quot;Empty or no reply&quot; if msg[0].length == 0
+      raise msg[0] if msg[0] != &quot;Okay&quot;
+    rescue =&gt; e
+      raise e
+    end
+  end
+end
+
+while 1 do
+
+  # Connect to the ScopePort server.
+  begin
+    con = Conversation.new hostname, port
+  rescue =&gt; e
+    puts &quot;Could not connect to ScopePort server: #{e}&quot;
+    con.close
+    sleep(60)
+    next
+  end
+
+  # Log in
+  begin
+    con.login host_id, password
+  rescue =&gt; e
+    puts &quot;Could not log in: #{e}&quot;
+    con.close
+    sleep(60)
+    next
+  end
+
+  # Send sensor data
+  begin
+    con.send_sensor_data host_id, &quot;sensor_,cpu5&quot;, &quot;5.2&quot;
+  rescue =&gt; e
+    puts &quot;Could not send sensor data: #{e}&quot;
+    con.close
+    sleep(60)
+    next
+  end
+  
+  # All done. Close socket.
+  con.close
+
+  sleep 60
+end</diff>
      <filename>scopeport-client.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>4128b0de316caa3fd1f4c3fb447665915b432fa9</id>
    </parent>
  </parents>
  <author>
    <name>Lennart Koopmann</name>
    <email>lennart@sundaysister.(none)</email>
  </author>
  <url>http://github.com/lennartkoopmann/scopeport-client-ruby/commit/665e4d69a93c73fd8055511aae55e88afcfb42c2</url>
  <id>665e4d69a93c73fd8055511aae55e88afcfb42c2</id>
  <committed-date>2009-06-12T14:40:00-07:00</committed-date>
  <authored-date>2009-06-12T14:40:00-07:00</authored-date>
  <message>First version of the Ruby client. Connects, logs in and sends sample sensor data every 60 seconds.</message>
  <tree>e8d00f1d18480f1d44b8db99d0757d4ff63c1c3d</tree>
  <committer>
    <name>Lennart Koopmann</name>
    <email>lennart@sundaysister.(none)</email>
  </committer>
</commit>
