Exemplo n.º 1
0
 def test_udpsender_loopback_IPv6(self):
     l = socket.socket(ip.PF_INET6, socket.SOCK_DGRAM)
     l.bind(("::1",0))
     addr = l.getsockname()[:2]
     s = UdpSender("udp://[%s]:%d"%addr)
     url = s.url()
     peerurl = s.peerUrl()
     self.assertEqual((peerurl.site.host, peerurl.site.port), 
                      l.getsockname()[:2])        
     n = s.send(self.data)
     self.assertEqual(n, len(self.data))
     time.sleep(_sec)
     data, source = l.recvfrom(1024)
     self.assertEqual(data, self.data)
     self.assertEqual(source[:2], (url.site.host, url.site.port))
     l.close()
Exemplo n.º 2
0
 def test_udpsender_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 = socket.socket(ip.PF_INET6, socket.SOCK_DGRAM)
         l.bind(("localhost",0))
         addr, port = l.getsockname()[:2]
         s = UdpSender("udp://localhost:%d"%port, ip.PF_INET6)
         url = s.url()
         peerurl = s.peerUrl()
         self.assertEqual((peerurl.site.host, peerurl.site.port), 
                          l.getsockname()[:2])        
         n = s.send(self.data)
         self.assertEqual(n, len(self.data))
         time.sleep(_sec)
         data, source = l.recvfrom(1024)
         self.assertEqual(data, self.data)
         self.assertEqual(source[:2], (url.site.host, url.site.port))
         l.close()
Exemplo n.º 3
0
 def test_udpsender_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 = socket.socket(ip.PF_INET, socket.SOCK_DGRAM)
         l.bind((hostname, 0))
         addr, port = l.getsockname()[:2]
         s = UdpSender("udp://%s:%d"%(hostname, port), ip.PF_INET)
         url = s.url()
         peerurl = s.peerUrl()
         sockname = l.getsockname()[:2]
         self.assertEqual((peerurl.site.host, peerurl.site.port), sockname)        
         n = s.send(self.data)
         self.assertEqual(n, len(self.data))
         time.sleep(_sec)
         data, source = l.recvfrom(1024)
         self.assertEqual(data, self.data)
         self.assertEqual(source, (url.site.host, url.site.port))
         l.close()