From: Nat Pryce Date: 2001-08-08T09:23:16+09:00 Subject: [ruby-talk:19320] Problems with UDP on Windows This is a multi-part message in MIME format. ------=_NextPart_000_0067_01C11FA7.4CC0D570 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable require 'socket' Am I being really stupid? I cannot get UDP communication to work on = Windows 2000. This this program fails as soon as the server tries to = reply to the client. def server s =3D UDPSocket.new s.bind( nil, 4000 ) =20 msg,sender =3D s.recvfrom( 1024, 0 ) domain,port,hostname,hostaddr =3D sender =20 p sender s.send( msg.reverse, 0, hostaddr, port ) end def client s =3D UDPSocket.new s.send( "hello", 0, 'localhost', 4000 ) msg,sender =3D s.recvfrom( 1024, 0 ) p msg p sender end if ARGV[0] =3D=3D "server" server elsif ARGV[0] =3D=3D "client" client else puts "usage: #{$0} {server|client}" end The server prints the error message: demo_udp.rb:15:in `send': Invalid argument - "sendto(2)" (Errno::EINVAL) from demo_udp.rb:15:in `server' from demo_udp.rb:28 And the client prints the error message: demo_udp.rb:21:in `recvfrom': Invalid argument - "recvfrom(2)" = (Errno::EINVAL from demo_udp.rb:21:in `client' from demo_udp.rb:30 But the client has already sent a message to the server (using sendto) = and the server has already received a message from the client (using = recvfrom), and both recvfrom calls are identical, and the only = difference between the sendto calls is that the server is usnig address = data provided by the client, so it should be correct. Any help will be greatly appreciated. ------=_NextPart_000_0067_01C11FA7.4CC0D570 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

require 'socket'

Am I being really stupid?  I cannot get UDP communication = to work=20 on Windows 2000.  This this program fails as soon as the server = tries to=20 reply to the client.
 
def server
    s =3D = UDPSocket.new
   =20 s.bind( nil, 4000 )
   
    = msg,sender =3D=20 s.recvfrom( 1024, 0 )
    = domain,port,hostname,hostaddr =3D=20 sender
   
    p=20 sender
    s.send( msg.reverse, 0, hostaddr, port=20 )
end
 
def client
    s =3D = UDPSocket.new
   =20 s.send( "hello", 0, 'localhost', 4000 )
    msg,sender = =3D=20 s.recvfrom( 1024, 0 )
    p msg
    = p=20 sender
end
 

if ARGV[0] =3D=3D "server"
    = server
elsif ARGV[0] =3D=3D=20 "client"
    client
else
    puts = "usage:=20 #{$0} {server|client}"
end
 
The server prints the error message:
 
demo_udp.rb:15:in `send': Invalid argument - "sendto(2)"=20 (Errno::EINVAL)
        from=20 demo_udp.rb:15:in `server'
        = from=20 demo_udp.rb:28
 
And the client prints the error message:
 
demo_udp.rb:21:in `recvfrom': Invalid argument - "recvfrom(2)"=20 (Errno::EINVAL
        from=20 demo_udp.rb:21:in `client'
        = from=20 demo_udp.rb:30
 
But the client has already sent a message to the server (using = sendto) and=20 the server has already received a message from the client (using = recvfrom), and=20 both recvfrom calls are identical, and the only difference between the = sendto=20 calls is that the server is usnig address data provided by the client, = so it=20 should be correct.
 
Any help will be greatly appreciated.
 
------=_NextPart_000_0067_01C11FA7.4CC0D570--