def create_socket
      socket = ::Socket.new(::Socket::AF_INET, ::Socket::SOCK_STREAM, 0)
      sockaddr = ::Socket.sockaddr_in(PORTS.sample, self.hostname)
      begin # emulate blocking connect
        socket.connect_nonblock(sockaddr)
      rescue IO::WaitWritable
        IO.select(nil, [socket]) # wait 3-way handshake completion
        begin
          socket.connect_nonblock(sockaddr) # check connection failure
        rescue Errno::EISCONN
        end
      end
      socket
    end
def create_socket
      socket = ::Socket.new(::Socket::AF_INET, ::Socket::SOCK_STREAM, 0)
      sockaddr = ::Socket.sockaddr_in(PORTS.sample, self.hostname)
      begin # emulate blocking connect
        socket.connect_nonblock(sockaddr)
      rescue IO::WaitWritable
        IO.select(nil, [socket]) # wait 3-way handshake completion
        begin
          socket.connect_nonblock(sockaddr) # check connection failure
        rescue Errno::EISCONN
        end
      end
      socket
    end
Create a new socket connection with DeathByCaptcha API.
 This method is necessary because Ruby 1.9.7 doesn't support connection
 timeout and only Ruby 2.2.0 fixes a bug with unsafe sockets threads.

 In Ruby >= 2.2.0, this could be implemented as simply as:
 ::Socket.tcp(HOST, PORTS.sample, connect_timeout: 0)