Created
April 9, 2011 18:52
-
-
Save seungjin/911668 to your computer and use it in GitHub Desktop.
ruby time server and client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Date Time Server - server side using thread | |
# usage: ruby p068dtserver.rb | |
require "socket" | |
dts = TCPServer.new('localhost', 20000) | |
loop do | |
Thread.start(dts.accept) do |s| | |
print(s, " is accepted\n") | |
s.write(Time.now) | |
print(s, " is gone\n") | |
s.close | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'socket' | |
streamSock = TCPSocket.new( "127.0.0.1", 20000 ) | |
#streamSock.send( "Hello\n" ) | |
str = streamSock.recv( 100 ) | |
print str | |
streamSock.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment