Skip to content

Instantly share code, notes, and snippets.

@jarib
Created March 26, 2009 19:28
Show Gist options
  • Save jarib/86262 to your computer and use it in GitHub Desktop.
Save jarib/86262 to your computer and use it in GitHub Desktop.
$ ruby socket_stuff.rb
tcp6 0 0 localhost.6000 *.* LISTEN
:mri
{:read=>"foo"}
tcp6 0 0 localhost.6000 *.* LISTEN
tcp6 0 0 localhost.49830 localhost.6000 TIME_WAIT
:jruby
-e:1:in `new': Connection refused - Connection refused (Errno::ECONNREFUSED)
from -e:1
$ jruby socket_stuff.rb
tcp4 0 0 localhost.6000 *.* LISTEN
tcp6 0 0 localhost.49830 localhost.6000 TIME_WAIT
:mri
{:read=>"foo"}
tcp4 0 0 localhost.6000 *.* LISTEN
tcp6 0 0 localhost.49830 localhost.6000 TIME_WAIT
tcp4 0 0 localhost.49834 localhost.6000 TIME_WAIT
:jruby
{:read=>"foo"}
$
require "socket"
$stdout.sync = true
def wait(t)
sleep 0.1 until t.status == "sleep"
system "netstat -a | grep 6000"
end
s = TCPServer.new('localhost', 6000)
t = Thread.new do
loop {
sock = s.accept
p :read => sock.read
sock.close
}
end
code = 's=TCPSocket.new("localhost", 6000); s.write("foo"); s.close'
wait(t)
p :mri
system "ruby -r socket -e '#{code}'"
wait(t)
p :jruby
system "jruby -r socket -e '#{code}'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment