Socket.tcp(host, port, local_host=nil, local_port=nil, [opts]) {|socket| ... }
Socket.tcp(host, port, local_host=nil, local_port=nil, [opts])
Socket.tcp(host, port, local_host=nil, local_port=nil, [opts])
Class Public methods
creates a new socket object connected to host:port using TCP/IP.
If local_host:local_port is given, the socket is bound to it.
The optional last argument opts is options represented by a hash. opts may have following options:
- :connect_timeout
-
specify the timeout in seconds.
If a block is given, the block is called with the socket. The value of the block is returned. The socket is closed when this method returns.
The optional last argument opts is options represented by a hash. opts may have following options:
- :timeout
-
specify the timeout in seconds.
If no block is given, the socket is returned.
Socket.tcp("www.ruby-lang.org", 80) {|sock| sock.print "GET / HTTP/1.0\r\nHost: www.ruby-lang.org\r\n\r\n" sock.close_write puts sock.read }
Please login to continue.