Esempio n. 1
0
 def recv(self, close_on_timeout=False, **kwargs):
     if not self.socket:
         raise ConnectFirst()
     try:
         return _recv(self.socket, socket_type="tcp", **kwargs)
     except TimeoutError:
         if close_on_timeout:
             self.close()
         return None
Esempio n. 2
0
 def recv(self, close_on_timeout=False, **kwargs):
     if not self.client:
         raise NoClient()
     try:
         res = _recv(self.client, socket_type="tcp", **kwargs)
     except TimeoutError:
         if close_on_timeout:
             self.close()
         return None
     return res
Esempio n. 3
0
 def receive(self, host, port, timeout=None, **kwargs):
     s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     if host == broadcast_address:
         s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
     s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     try:
         s.bind((host, port))
     except socket.error:
         raise Exception("Address %s:%i already in use" % (host, port))
     data, addr = _recv(s, timeout=timeout, socket_type="udp", **kwargs)
     return data, addr
Esempio n. 4
0
 def recv(self, **kwargs):
     if not self.socket:
         raise ConnectFirst()
     return _recv(self.socket, socket_type="tcp", **kwargs)