From: "Brian Schröder" Date: 2005-10-02T09:09:47+09:00 Subject: Re: Sending YAML over TCP On 02/10/05, lists wrote: > Hi, > I'm trying to send simple data structures (hashes) to a daemon > process one one machine from a client process via TCP. I thought the > best way to do this would be with XML or YAML. Here's my simple server: > > [snip code] > > Obviously I don't know what I'm doing :-) The above client/server > works for my simple purposes, but I wanted to know if there's a > better way to pass hashes from the client to the server and back. > I'd prefer to stick with YAML (rather than XML) if possible. > > Thanks, > Ryan > Hello Ryan, this works, but maybe drb is better suited for your needs: bschroed@black:~/svn/projekte/yamlserver$ cat server.rb require 'socket' require 'yaml' server = TCPServer.new('127.0.0.1', 8585) while (session = server.accept) Thread.new(session) do | s | p YAML::load(s) s.close end end bschroed@black:~/svn/projekte/yamlserver$ cat client.rb require 'socket' require 'yaml' hash = { 'one'=>'1', 'two'=>'2'} client = TCPSocket.new('127.0.0.1', 8585) client.puts hash.to_yaml client.close regards, Brian -- http://ruby.brian-schroeder.de/ Stringed instrument chords: http://chordlist.brian-schroeder.de/