@asyncio.coroutine<EOL>def connect(host='<STR_LIT:localhost>',<EOL>port=<NUM_LIT>,<EOL>username='<STR_LIT>', password='<STR_LIT>',<EOL>virtual_host='<STR_LIT:/>',<EOL>on_connection_close=None, *,<EOL>loop=None, sock=None, **kwargs):
from .protocol import AMQP<EOL>from .routing import Dispatcher<EOL>from .connection import open_connection<EOL>loop = asyncio.get_event_loop() if loop is None else loop<EOL>if sock is None:<EOL><INDENT>kwargs['<STR_LIT:host>'] = host<EOL>kwargs['<STR_LIT:port>'] = port<EOL><DEDENT>else:<EOL><INDENT>kwargs['<STR_LIT>'] = sock<EOL><DEDENT>dispatcher = Dispatcher()<EOL>def protocol_factory():<EOL><INDENT>return AMQP(dispatcher, loop, close_callback=on_connection_close)<EOL><DEDENT>transport, protocol = yield from loop.create_connection(protocol_factory, **kwargs)<EOL>sk = transport.get_extra_info('<STR_LIT>')<EOL>if (sk.family in (socket.AF_INET, socket.AF_INET6)) and (sk.proto in (<NUM_LIT:0>, socket.IPPROTO_TCP)):<EOL><INDENT>sk.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, <NUM_LIT:1>)<EOL><DEDENT>connection_info = {<EOL>'<STR_LIT:username>': username,<EOL>'<STR_LIT:password>': password,<EOL>'<STR_LIT>': virtual_host<EOL>}<EOL>connection = yield from open_connection(<EOL>loop, transport, protocol, dispatcher, connection_info)<EOL>return connection<EOL>
Connect to an AMQP server on the given host and port.

Log in to the given virtual host using the supplied credentials.
This function is a :ref:`coroutine <coroutine>`.

:param str host: the host server to connect to.
:param int port: the port which the AMQP server is listening on.
:param str username: the username to authenticate with.
:param str password: the password to authenticate with.
:param str virtual_host: the AMQP virtual host to connect to.
:param func on_connection_close: function called after connection lost.
:keyword BaseEventLoop loop: An instance of :class:`~asyncio.BaseEventLoop` to use.
    (Defaults to :func:`asyncio.get_event_loop()`)
:keyword socket sock: A :func:`~socket.socket` instance to use for the connection.
    This is passed on to :meth:`loop.create_connection() <asyncio.BaseEventLoop.create_connection>`.
    If ``sock`` is supplied then ``host`` and ``port`` will be ignored.

Further keyword arguments are passed on to :meth:`loop.create_connection() <asyncio.BaseEventLoop.create_connection>`.

This function will set TCP_NODELAY on TCP and TCP6 sockets either on supplied ``sock`` or created one.

:return: the :class:`Connection` object.