blob: 5f2ec52e5eafebdaf8d7516ad307261e4841aaf7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# $Id: server_1_ppm.rb,v 1.2 2006-03-15 04:40:47 matju Exp $
require "socket"
picture = File.open("../images/teapot.ppm") {|x| x.read }
serv = TCPServer.new 4242
loop {
puts "waiting for connection (port 4242)"
sock = serv.accept
begin
loop {
sock.write picture
puts "wrote one picture"
}
rescue Errno::EPIPE # Broken Pipe
puts "connection closed (by client)"
# it's ok, go back to waiting.
end
}
|