Permalink
Browse files

sample socket client

  • Loading branch information...
shokai committed Oct 5, 2010
1 parent 5d59ea1 commit 963e4c607ec2cf0aea17abd3447e812d825d3098
Showing with 32 additions and 0 deletions.
  1. +32 −0 samples/client.rb
View
@@ -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.