On 16 Apr 2008, at 13:08, Kr Alfabeta wrote:
>
>> If socket.connect does not succeed, it will raise an error, otherwise
>> you should be good to go. See the documentation here
>> (http://ruby-doc.org/stdlib/libdoc/socket/rdoc/classes/Socket.html)  
>> and
>> here
>> (http://ruby-doc.org/stdlib/libdoc/socket/rdoc/classes/Socket.html).
>>
>> Does that help?
>>
>> -Justin
>
> Well, I was trying this but it returns the same response when it's
> possible to connect to IP but not to port (example: port 1234 not  
> binded
> in server but the response is the same as with binded port 80)

UDP is connectionless, unreliable, and will not report errors to you  
for foreign "connections". I am unsure as to why the api is like it  
is, other than that it follows iirc, the bsd sockets api.

I know there's a connect method, but that is merely for convenience.  
Look at UDP(4) (that is, man 4 udp).

The only reason you would be getting strange errors is if you're  
testing over localhost. Errors for UDP packets are irregular at best:

 >> raggi@mbk:~$ irb
 >> require 'socket'
=> true
 >> sock = UDPSocket.new
=> #<UDPSocket:0x8320c>
 >> sock.connect('beith', 1234)
=> 0
 >> sock.write('foo')
=> 3
 >> sock.write('foo')
Errno::ECONNREFUSED: Connection refused
	from (irb):5:in `write'
	from (irb):5
	from :0
 >> sock.write('foo')
=> 3
 >> sock.write('foo')
Errno::ECONNREFUSED: Connection refused
	from (irb):7:in `write'
	from (irb):7
	from :0

Again, what the man page is saying should make the above more clear.

Somewhat reminds me of the time a company asked me to use the packet  
arrival order of UDP data in order to reconstruct long messages, lol.


>
> -- 
> Posted via http://www.ruby-forum.com/.
>