Skip to content

Instantly share code, notes, and snippets.

@seungjin
Created April 9, 2011 18:52
Show Gist options
  • Save seungjin/911668 to your computer and use it in GitHub Desktop.
Save seungjin/911668 to your computer and use it in GitHub Desktop.
ruby time server and client
# 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
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