def _connect(self, addr): print "Begin _connect" self._init_client_mode() self.connected = True self.python_inbound_handler = PythonInboundHandler(self) bootstrap = Bootstrap().group(NIO_GROUP).channel(NioSocketChannel) # add any options # FIXME really this is just for SSL handling if self.connect_handlers: for handler in self.connect_handlers: print "Adding connect handler", handler bootstrap.handler(handler) else: print "Adding read adapter", self.python_inbound_handler bootstrap.handler(self.python_inbound_handler) # FIXME also support any options here def completed(f): self._notify_selectors() print "Connection future - connection completed", f host, port = addr future = bootstrap.connect(host, port) future.addListener(completed) self._handle_channel_future(future, "connect") self.channel = future.channel() print "Completed _connect on {}".format(self)
def _datagram_connect(self): # FIXME raise exception if not of the right family if not self.connected: print "Connecting datagram socket to", self.bind_addr self.connected = True self.python_inbound_handler = PythonInboundHandler(self) bootstrap = Bootstrap().group(NIO_GROUP).channel(NioDatagramChannel) bootstrap.handler(self.python_inbound_handler) # add any options # such as .option(ChannelOption.SO_BROADCAST, True) future = bootstrap.bind(_get_inet_addr(self.bind_addr)) self._handle_channel_future(future, "bind") self.channel = future.channel() print "Completed _datagram_connect on {}".format(self)