'Opens a new session with a given client.
Arguments:
client -- An XMPP client.
callback -- An optional callback which can be used to track
the starting state of the session.'

@classmethod
def new_session_with_client(cls, client, callback=None):

    with Remote._lock:
        if (client.boundjid.bare in cls._sessions):
            raise RemoteException('There    already    is    a    session    associated    with    these    credentials!')
        else:
            cls._sessions[client.boundjid.bare] = client
    def _session_close_callback():
        with Remote._lock:
            del cls._sessions[client.boundjid.bare]
    result = RemoteSession(client, _session_close_callback)
    client.plugin['xep_0009'].xmpp.add_event_handler('jabber_rpc_method_call', result._on_jabber_rpc_method_call, threaded=True)
    client.plugin['xep_0009'].xmpp.add_event_handler('jabber_rpc_method_response', result._on_jabber_rpc_method_response, threaded=True)
    client.plugin['xep_0009'].xmpp.add_event_handler('jabber_rpc_method_fault', result._on_jabber_rpc_method_fault, threaded=True)
    client.plugin['xep_0009'].xmpp.add_event_handler('jabber_rpc_error', result._on_jabber_rpc_error, threaded=True)
    if (callback is None):
        start_event_handler = result._notify
    else:
        start_event_handler = callback
    client.add_event_handler('session_start', start_event_handler)
    if client.connect():
        client.process(threaded=True)
    else:
        raise RemoteException('Could    not    connect    to    XMPP    server!')
    pass
    if (callback is None):
        result._wait()
    return result
