Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 21 lines (17 sloc) 0.352 kb
511dc44 initial import
Laurent Sansonetti authored
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 loop do
12 Thread.start(gs.accept) do |s|
13 print(s, " is accepted\n")
14 while line = s.gets
15 s.write(line)
16 end
17 print(s, " is gone\n")
18 s.close
19 end
20 end
Something went wrong with that request. Please try again.