- 追加された行はこの色です。
- 削除された行はこの色です。
[[3D]]
* サンプルクライアント by ruby [#k5a101ca]
require 'socket'
class Client
attr :socket
def open(host)
@socket = TCPSocket.open(host, 3100)
end
def close
@socket.close
end
def send(msg)
str = [msg.length].pack('N') + msg
@socket.write(str)
end
def recv
nsize = @socket.read(4)
size = nsize.unpack('N')
@socket.read(size[0])
end
end
# Main
client = Client.new
client.open 'localhost'
Thread.start {
# output to STDOUT
while true
puts client.recv
end
}
# input from STDIN
while true
l = gets
client.send l
end
* usage [#s439d534]
$ ruby sample-agent.rb > /tmp/xxx.log
(scene rsg/agent/nao/nao.rsg)
(init (unum 0) (team RR))
* 組込Ruby参考 [#e830860a]
- [[SWIG:http://www.swig.org/]]
- [[RubyEmbed:http://raa.ruby-lang.org/project/rubyembed/]]