the server will print out 2 line of data e.g.:
[“sample”, [“AF_INET”, 1339, “XRFANG-OTM”, “192.168.1.101”]]
[“sample”, [“AF_INET”, 1339, “XRFANG-OTM”, “192.168.1.101”]]
but the client only sent one packet.
if the client send data more than 10 bytes, the server will crash! I
don’t know how to set the “recvfrom” so that it can receive ANY byte of
data. i.e. when the client supplied more than the maximum wanted data
for
the server, the rest should be received on the next call to recvfrom, or
at
least, it should simply discard the excessive data, it must not crash
the
server anyway.
yuray@yuray:~/r$
yuray@yuray:~/r$ cat s.rb
require ‘socket’
server = UDPSocket.open
server.bind(‘0.0.0.0’, 4321)
while true do
p server.recvfrom(10)
end
Works for me. Client and server was running on single machine.
What is ruby version?
Can you run the test client and server on single machine?
Can you test with a new clear ruby installation without any packages ?
the server will print out 2 line of data e.g.:
[“sample”, [“AF_INET”, 1339, “XRFANG-OTM”, “192.168.1.101”]]
[“sample”, [“AF_INET”, 1339, “XRFANG-OTM”, “192.168.1.101”]]
but the client only sent one packet.
Can’t reproduce that. Does it happen repeatably? Does it happen if you
do
server.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
after opening the server socket?
I’m on WinXP, with ruby-1.8.2 from the installer.
if the client send data more than 10 bytes, the server will crash! I
don’t know how to set the “recvfrom” so that it can receive ANY byte of
data. i.e. when the client supplied more than the maximum wanted data
for the server, the rest should be received on the next call to
recvfrom, or at least, it should simply discard the excessive data, it
must not crash the server anyway.
I see that too:
server.rb:6:in `recvfrom’: A message sent on a datagram socket was
larger than the internal message buffer or some other network limit, or
the buffer used to receive a datagram into was smaller than the datagram
itself. - recvfrom(2) (Errno::EMSGSIZE)
from server.rb:6
That doesn’t seem like winsock has correctly implemented UDP. Shouldn’t
recvfrom discard extra bytes?
Googling for “winsock udp broadcast” shows that others have found
similar problems. Particularly:
I guess this means the receiver needs to (a) know the max size of
legitimate data and (b) handle EMSGSIZE (at least logging an error, but
maybe not exiting).
Useful to know. Thanks!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.