Skip to content

Commit

Permalink
sample socket client
Browse files Browse the repository at this point in the history
  • Loading branch information
shokai committed Oct 5, 2010
1 parent 5d59ea1 commit 963e4c6
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions samples/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'rubygems'
require 'socket'
require 'eventmachine'

HOST = "localhost"
PORT = 8782

begin
s = TCPSocket.open(HOST, PORT)
rescue => e
STDERR.puts e
exit 1
end

EventMachine::run do
EventMachine::defer do
loop do
res = s.gets
exit unless res
puts res
end
end

EventMachine::defer do
loop do
s.puts gets
end
end
end

0 comments on commit 963e4c6

Please sign in to comment.