tcp(host, port, local_host = nil, local_port = nil, connect_timeout: nil) public

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:


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.

If no block is given, the socket is returned.

Socket.tcp("", 80) {|sock|
  sock.print "GET / HTTP/1.0\r\nHost:\r\n\r\n"
Show source
Register or log in to add new notes.