From: Robby Russell Date: 2005-10-02T09:39:10+09:00 Subject: Re: Sending YAML over TCP On Sun, 2005-10-02 at 08:23 +0900, 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: > > --- > require 'socket' > > server = TCPServer.new('127.0.0.1', 8080) > > while (session = server.accept) > session.puts session.gets > session.close > end > --- > > Here's my simple client: > > --- > require 'socket' > require 'yaml' > require 'base64' > > hash = { 'one'=>'1', 'two'=>'2'} # Send this to the server and get it > back > > client = TCPSocket.new('127.0.0.1', 8080) > client.puts Base64.encode64(h.to_yaml) > hash = YAML.load( Base64.decode64(client.gets) ) > client.close > p hash > --- > > 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 > Will all the clients be based in Ruby? If so, you might look at DRb. http://segment7.net/projects/ruby/drb/introduction.html -Robby -- /****************************************************** * Robby Russell, Owner.Developer.Geek * PLANET ARGON, Open Source Solutions & Web Hosting * Portland, Oregon | p: 503.351.4730 | f: 815.642.4068 * www.planetargon.com | www.robbyonrails.com * Programming Rails | www.programmingrails.com *******************************************************/