'Set the socket to use for the stream.
The filesocket will be recreated as well.
:param socket: The new socket object to use.
:param bool ignore: If ``True``, don\'t set the connection
state to ``\'connected\'``.'

def set_socket(self, socket, ignore=False):

    self.socket = socket
    if (socket is not None):
        if (sys.version_info < (3, 0)):
            self.filesocket = FileSocket(self.socket)
        else:
            self.filesocket = self.socket.makefile(u'rb', 0)
        if (not ignore):
            self.state._set_state(u'connected')
