Exemplo n.º 1
0
 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')
Exemplo n.º 2
0
 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()
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
 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')
Exemplo n.º 5
0
 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')
Exemplo n.º 6
0
 def _check_socket_connected(self):
     if not self.is_connected():
         raise PTCError('socket not connected')
Exemplo n.º 7
0
 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()