sample/tsvr.rb


DEFINITIONS

This source file includes following functions.


   1  # socket example - server side using thread
   2  # usage: ruby tsvr.rb
   3  
   4  require "socket"
   5  
   6  gs = TCPserver.open(0)
   7  addr = gs.addr
   8  addr.shift
   9  printf("server is on %s\n", addr.join(":"))
  10  
  11  while TRUE
  12    Thread.start(gs.accept) do |s|
  13      print(s, " is accepted\n")
  14      while s.gets
  15        s.write($_)
  16      end
  17      print(s, " is gone\n")
  18      s.close
  19    end
  20  end