-
-
Save rickhull/607395 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'socket' | |
require 'rubygems' | |
require 'nokogiri' | |
PORT = rand(65535 - 1024) + 1024 | |
sthread = Thread.new { | |
s = TCPServer.new(PORT).accept | |
puts "[SERVER] Client connected." | |
s.write('<foo>') | |
5.times { | |
sleep rand(0.0) | |
s.write('<test>') | |
s.write('DATA' * 1000) | |
s.write('</test>') | |
puts "[SERVER] Sent a chunk." | |
} | |
s.write('</foo>') | |
puts "[SERVER] Document transmitted." | |
puts "[SERVER] Holding the socket open..." | |
5.downto(1) { |count| | |
puts "[SERVER] #{count}" | |
sleep 1 | |
} | |
s.close | |
puts "[SERVER] Closed the socket." | |
} | |
c = TCPSocket.new('', PORT) | |
Nokogiri::XML::Reader.from_io(c).each { |node| | |
puts node.name #"[CLIENT] Received <#{node.name}>" | |
} | |
puts "Document received." | |
sthread.join |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[SERVER] Client connected. | |
[SERVER] Sent a chunk. | |
foo | |
test | |
#text | |
test | |
test | |
[SERVER] Sent a chunk. | |
#text | |
test | |
test | |
[SERVER] Sent a chunk. | |
#text | |
test | |
test | |
[SERVER] Sent a chunk. | |
#text | |
test | |
test | |
[SERVER] Sent a chunk. | |
[SERVER] Document transmitted. | |
[SERVER] Holding the socket open... | |
[SERVER] 5 | |
[SERVER] 4 | |
[SERVER] 3 | |
[SERVER] 2 | |
[SERVER] 1 | |
[SERVER] Closed the socket. | |
#text | |
test | |
foo | |
Document received. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment