From: Brian Candler Date: 2004-09-13T21:23:05+09:00 Subject: Re: UDPSocket - script crash On Mon, Sep 13, 2004 at 04:34:56AM +0900, mark shennce wrote: > if there is no peer for this udp socket which > was created with > > $sock = UDPSocket.new > > the script crash with the message > 'connection was closed by peer'. > > How to avoid this crash? Can you give a *complete* program which causes it, rather than fragments? The following program works fine for me (FreeBSD) ------------------------------------------------------------------- require 'socket' def mysend(str) begin $sock.send(str, 0, "127.0.0.1", 9999) rescue Exception => e p "Oops: #{e}" end end $sock = UDPSocket.new mysend("hello") ------------------------------------------------------------------- > def Send str Aside: method names usually don't start with uppercase letters, and you might be better to avoid them. Incidetnally, some care also needs to be taken with the method name 'send', because for most objects it's used to for method dispatch: irb(main):007:0> 3.send('+',5) => 8 Regards, Brian.