Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Forked from rickhull/gist:606800
Created October 1, 2010 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tenderlove/606809 to your computer and use it in GitHub Desktop.
Save tenderlove/606809 to your computer and use it in GitHub Desktop.
require 'socket'
require 'rubygems'
require 'nokogiri'
PORT = rand(65535 - 1024) + 1024
sthread = Thread.new {
s = TCPServer.new(PORT).accept
s.write('<foo>')
10.times {
s.write('<test>')
s.write('DATA' * 1000)
s.write('</test>')
}
sleep 30
s.write('</foo>')
s.close
}
c = TCPSocket.new('', PORT)
Nokogiri::XML::Reader.from_io(c).each { |node|
puts node.name
}
sthread.join
Nokogiri::XML::Reader.from_io(c).each { |node|
puts node.name
}
sthread.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment