Last active
August 29, 2015 14:11
-
-
Save jakenotjacob/3e878d7316c10b3104d1 to your computer and use it in GitHub Desktop.
Rescue Socket error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[14] pry(main)> A.new 'irc.freenode.net', 6667 | |
=> #<A:0x000000034889a8 @sock=#<TCPSocket:fd 8>> | |
[20] pry(main)> A.new 'localhost', 1233 | |
Errno::ECONNREFUSED: Connection refused - connect(2) for "localhost" port 1233 | |
from (pry):6:in `initialize' | |
[27] pry(main)> A.new 'localhostasdf', 1233 | |
Invalid host or port! | |
=> #<A:0x00000003263c18> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A | |
attr_accessor :sock | |
def initialize(host, port) | |
@host = host | |
@port = port | |
begin | |
@sock = TCPSocket.new host, port | |
rescue SocketError | |
puts "Invalid host or port!" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment