TCP woes with JRuby
I’ve been trying (again) to get my Ruby DNS library working with JRuby. I’ve been having some difficulties - not all of which are JRuby’s fault!
I need to be able to send data from a TCP port and receive a response. Many connections may be running from the same socket, and I need to be able to tell where a response has come from. The easy way to do this would be use TCPSocket#recvfrom - unfortunately, that raises an exception on Windows for Ruby 1.8.5 and 1.8.6 in MRI.
That leaves me with the option of creating a Socket directly, which is what pnet-dns does. Unfortunately, this API is still not fully supported by JRuby, so I’m stuck with TCPSocket. However, I thought I could still do something like :
if (/java/=~RUBY_PLATFORM)
sock = TCPSocket.new(ns, dstport, srcaddr, srcport)
else
sock = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
sockaddr = Socket.pack_sockaddr_in( srcport, srcaddr )
sock.bind( sockaddr )
sockaddr = Socket.pack_sockaddr_in( dstport, ns )
sock.connect(sockaddr)
end
Unfortunately, JRuby doesn’t support TCPSocket.new with 4 parameters. *sigh*

(1 votes, average: 4 out of 5)
July 7th, 2007 at 1:36 am
The TCPSocket.new(a, b, c, d) missing would qualify as a bug. Can you file it at jira.codehaus.org/browse/JRUBY, perhaps with a description of what it’s supposed to do?