Windows UDP oddities/failures


(Steve Tuckner) #1

I am having a peculiar problem with UDP in windows. A simple test that
runs under linux fails in windows. Below are two scripts one for a
server and one for a client. The server starts by waiting for a packet
and then when it gets on it sends a response. The client starts by
sending a packet and waiting for a response.

On Linux the server prints the frame received and and waits for the next
one. The client prints the frame it received back from the server and exits.

On Windows, if the bind call is included, then the first packet never
gets sent by the client. If the bind call is ommitted, then the recvfrom
fails with

client.rb:12:in `recvfrom’: The network is busy.- recvfrom(2) (Errno::E054)

If the bind call is added back in after the connect call, then bind
fails with:

client.rb:11:in `bind’: Invalid argument - bind(2) (Errno::EINVAL)

Any ideas on this one?

The select on the client does succeed so that it knows there is
something to receive. It just can’t get its hands on it ;-(

Steve Tuckner

ruby 1.8.0 (2003-08-04) [i386-mswin32]
Windows XP

– Client.rb -------------------------
#!/usr/bin/env ruby

require “socket”

socket = UDPSocket.open
server.bind(nil, 1601)
socket.connect(“192.168.4.80”, 1600) # FIXME get port from send page
response
socket.send(“hello”, 0)
if select([socket], nil, nil, 3) then
p socket.recvfrom(64)
end

– Server.rb -------------------------
#!/usr/bin/env ruby

require “socket”

address = ARGV.shift or raise "ip address needed"
server = UDPSocket.open
server.bind(nil, 1600)
server.connect(address, 1601)
while true
p server.recvfrom(1200)
server.send(“hello”, 0)
end

Steve Tuckner