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
---
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.
why not drb - then you can pass any object and needed bother with yaml/xml,
etc. ??
-a
···
On Sun, 2 Oct 2005, 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
---
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
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
Your life dwells amoung the causes of death
Like a lamp standing in a strong breeze. --Nagarjuna
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'
On 02/10/05, lists <lists@kalama.no-ip.org> 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.
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
---
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.
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
---
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.
"YAML::load_documents is the most efficient way to load streaming data.
This applies as well to TCP sockets. Client/server applications which
communcate in YAML can pass the TCPSocket object directly to
YAML::load_documents for parsing a stream over TCP/IP."
I don't know if that has any relevance to your example (?).
- If not, please ignore.
thanks for the pointer. I have no idea if it is applicable in this
case. Just did a quick hack to show how sockets work, but I have to
admit I have never even used yaml.
regards,
Brian
···
On 02/10/05, daz <dooby@d10.karoo.co.uk> wrote:
Brian Schröder wrote:
>
> [YAML client/server code]
"YAML::load_documents is the most efficient way to load streaming data.
This applies as well to TCP sockets. Client/server applications which
communcate in YAML can pass the TCPSocket object directly to
YAML::load_documents for parsing a stream over TCP/IP."
I don't know if that has any relevance to your example (?).
- If not, please ignore.