From: lists Date: 2005-10-03T02:12:02+09:00 Subject: Re: Sending YAML over TCP Wow, I didn't know about drb. That does indeed do what I want more elegantly. Brian, I'm keeping you're example of sending YAML in case I need it for a different project. Thanks to all who replied. -Ryan On Oct 1, 2005, at 6:23 PM, 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 > >