示例#1
0
 def test_udplistener_loopback_IPv6(self):
     s = socket.socket(ip.PF_INET6, socket.SOCK_DGRAM)
     l = UdpListener("udp://[::1]:0")
     s.connect(l.name())
     s.send(self.data)
     time.sleep(_sec)
     data, source = l.receiveFrom()
     self.assertEqual(data, self.data)
     self.assertEqual(source, s.getsockname()[:2])
     s.close()
示例#2
0
 def test_udplistener_hostname_IPv6_reuse(self):
     hostname = socket.gethostname()
     try:
         hostaddress, hostport = ip.resolve(hostname, 0, ip.PF_INET6)
     except Exception:
         hostaddress, hostport = None, 0
     if hostaddress is not None:
         lock = UdpListener("udp://%s:0"%hostname, ip.PF_INET6, ("reuse",))
         port = lock.name()[1]
         self.assertRaises(Exception, UdpListener, 
                           "udp://%s:%d"%(hostname, port), ip.PF_INET6)
         l = UdpListener("udp://%s:%d"%(hostname, port),
                         ip.PF_INET6, ("reuse",))
         url = l.url()
         self.assertEqual(url.site.port, port)
         s = socket.socket(ip.PF_INET6, socket.SOCK_DGRAM)
         s.connect(l.name())
         sockname = s.getsockname()[:2]
         sockname = (sockname[0].partition("%")[0], sockname[1])
         s.send(self.data)
         time.sleep(_sec)
         if sys.platform in ("win32", "darwin"): data, source = lock.receiveFrom()
         else: data, source = l.receiveFrom()
         self.assertEqual(data, self.data)
         self.assertEqual(source, sockname)
         lock.close()
         s.close()
示例#3
0
 def test_udplistener_any_ip4(self):
     s = socket.socket(ip.PF_INET, socket.SOCK_DGRAM)
     l = UdpListener("udp://0.0.0.0:0")
     url = l.url()
     s.connect(("127.0.0.1", url.site.port))
     s.send(self.data)
     time.sleep(_sec)
     data, source = l.receiveFrom()
     self.assertEqual(data, self.data)
     self.assertEqual(source, s.getsockname())
     s.close()
示例#4
0
 def test_udplistener_empty_IPv4(self):
     l = UdpListener(family=ip.PF_INET)
     url = l.url()
     s = socket.socket(ip.PF_INET, socket.SOCK_DGRAM)
     s.connect(("127.0.0.1", url.site.port))
     s.send(self.data)
     time.sleep(_sec)
     data, source = l.receiveFrom()
     self.assertEqual(data, self.data)
     self.assertEqual(source, s.getsockname())
     s.close()
示例#5
0
 def test_udplistener_any_ip6(self):
     s = socket.socket(ip.PF_INET6, socket.SOCK_DGRAM)
     l = UdpListener("udp://[::]:0")
     url = l.url()
     s.connect(("::1", url.site.port))
     sockname = s.getsockname()
     sockname = (sockname[0].partition("%")[0], sockname[1])
     s.send(self.data)
     time.sleep(_sec)
     data, source = l.receiveFrom()
     self.assertEqual(data, self.data)
     self.assertEqual(source, sockname)
     s.close()
示例#6
0
 def test_udplistener_localhost_IPv6(self):
     try:
         hostaddress, hostport = ip.resolve("localhost", 0, ip.PF_INET6)
     except Exception:
         hostaddress, hostport = None, 0
     if hostaddress is not None:
         l = UdpListener("udp://localhost:0", ip.PF_INET6)
         s = socket.socket(ip.PF_INET6, socket.SOCK_DGRAM)
         s.connect(l.name())
         s.send(self.data)
         time.sleep(_sec)
         data, source = l.receiveFrom()
         self.assertEqual(data, self.data)
         self.assertEqual(source, s.getsockname()[:2])
         s.close()
示例#7
0
 def test_udplistener_hostname_IPv4(self):
     hostname = socket.gethostname()
     try:
         hostaddress, hostport = ip.resolve(hostname, 0, ip.PF_INET)
     except Exception:
         hostaddress, hostport = None, 0
     if hostaddress is not None:
         l = UdpListener("udp://%s:0"%hostname, ip.PF_INET)
         s = socket.socket(ip.PF_INET, socket.SOCK_DGRAM)
         s.connect(l.name())
         time.sleep(_sec)
         sockname = s.getsockname()
         s.send(self.data)
         data, source = l.receiveFrom()
         self.assertEqual(data, self.data)
         self.assertEqual(source, sockname)
         s.close()
示例#8
0
 def test_udplistener_loopback_IPv6_reuse(self):
     lock = UdpListener("udp://[::1]:0", options=("reuse",))
     port = lock.name()[1]
     self.assertRaises(Exception, UdpListener, 
                       "udp://[::1]:%d"%port)
     l = UdpListener("udp://[::1]:%d"%port, options=("reuse",))
     url = l.url()
     self.assertEqual(url.site.port, port)
     s = socket.socket(ip.PF_INET6, socket.SOCK_DGRAM)
     s.connect((url.site.host, url.site.port))
     s.send(self.data)
     time.sleep(_sec)
     if sys.platform in ("win32", ): data, source = lock.receiveFrom()
     else: data, source = l.receiveFrom()
     self.assertEqual(data, self.data)
     self.assertEqual(source, s.getsockname()[:2])
     lock.close()
     s.close()
示例#9
0
 def test_udplistener_any_ip4_reuse(self):
     lock = UdpListener("udp://0.0.0.0:0", options=("reuse",))
     port = lock.name()[1]
     s = socket.socket(ip.PF_INET, socket.SOCK_DGRAM)
     self.assertRaises(Exception, UdpListener, 
                       "udp://0.0.0.0:%d"%port)
     l = UdpListener("udp://0.0.0.0:%d"%port,("reuse",), 
                     options=("reuse",))
     url = l.url()
     self.assertEqual(url.site.port, port)
     s.connect(("localhost", url.site.port))
     s.send(self.data)
     time.sleep(_sec)
     if sys.platform in ("win32", "darwin"):data, source = lock.receiveFrom()
     else: data, source = l.receiveFrom()
     self.assertEqual(data, self.data)
     self.assertEqual(source, s.getsockname())
     lock.close()
     s.close()
示例#10
0
 def test_udplistener_empty_host_IPv6_reuse(self):
     lock = UdpListener("udp://[::]:0", options=("reuse",))
     port = lock.name()[1]
     self.assertRaises(Exception, UdpListener, 
                       "udp://:%d"%port, family=ip.PF_INET6)
     l = UdpListener("udp://:%d"%port,
                     family=ip.PF_INET6, options=("reuse",))
     url = l.url()
     self.assertEqual(url.site.port, port)
     s = socket.socket(ip.PF_INET6, socket.SOCK_DGRAM)
     s.connect(("::1", url.site.port))
     sockname = s.getsockname()
     sockname = (sockname[0].partition("%")[0], sockname[1])
     s.send(self.data)
     time.sleep(_sec)
     if sys.platform in ("win32", "darwin"): data, source = lock.receiveFrom()
     else: data, source = l.receiveFrom()
     self.assertEqual(data, self.data)
     self.assertEqual(source, sockname)
     lock.close()
     s.close()
示例#11
0
 def test_udplistener_localhost_IPv6_reuse(self):
     try:
         hostaddress, hostport = ip.resolve("localhost", 0, ip.PF_INET6)
     except Exception:
         hostaddress, hostport = None, 0
     if hostaddress is not None:
         lock = UdpListener("udp://localhost:0", ip.PF_INET6, ("reuse",))
         port = lock.name()[1]
         s = socket.socket(ip.PF_INET6, socket.SOCK_DGRAM)
         self.assertRaises(Exception, UdpListener, 
                           "udp://localhost:%d"%port, ip.PF_INET6)
         l = UdpListener("udp://localhost:%d"%port,
                         ip.PF_INET6, ("reuse",))
         url = l.url()
         self.assertEqual(url.site.port, port)
         s.connect((url.site.host, url.site.port))
         s.send(self.data)
         time.sleep(_sec)
         if sys.platform in ("win32", ): data, source = lock.receiveFrom()
         else: data, source = l.receiveFrom()
         self.assertEqual(data, self.data)
         self.assertEqual(source, s.getsockname()[:2])
         lock.close()
         s.close()