def connect(self, address_tuple, timeout=None): if not self.is_connected(): if not self.is_bound(): self.bind() self._connect(address_tuple, timeout) else: raise PTCError('socket already connected')
def accept(self): if self.state != LISTEN: raise PTCError('should listen first') self.connected_event = threading.Event() self.start_threads() # Esperar hasta que un cliente desee conectarse. self.connected_event.wait()
def start(self, target_ticks): with self.lock: if self.is_running(): raise PTCError('timer already running') self.target_ticks = target_ticks self.current_ticks = 0 self.running = True
def accept(self, timeout=None): if not self.is_connected() and self.is_bound(): self._accept(timeout) elif not self.is_connected(): self.listen() self._accept(timeout) else: raise PTCError('socket already connected')
def bind(self, address_tuple=None): if address_tuple is None: address = NULL_ADDRESS port = random.randint(1000, 60000) address_tuple = (address, port) if not self.is_bound(): self.protocol.bind(*address_tuple) self.sockname = address_tuple else: raise PTCError('socket already bound')
def _check_socket_connected(self): if not self.is_connected(): raise PTCError('socket not connected')
def send(self, data): with self.control_block: if not self.write_stream_open: raise PTCError('write stream is closed') self.control_block.to_out_buffer(data) self.packet_sender.notify()