aboutsummaryrefslogtreecommitdiff
path: root/externals/gridflow/extra/server_1_ppm.rb
blob: dad6d3f7668a711c00e32d153e2569a4b135c93c (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.1 2005-10-04 02:02:15 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
}