Example #1
0
 def testSend(self):
     ss = SU.createSocket(bind=("localhost", 0))
     port = ss.getsockname()[1]
     cs = SU.createSocket(connect=("localhost", port))
     SU.sendData(cs, tobytes("foobar!" * 10))
     cs.shutdown(socket.SHUT_WR)
     a = ss.accept()
     data = SU.receiveData(a[0], 5)
     self.assertEqual(tobytes("fooba"), data)
     data = SU.receiveData(a[0], 5)
     self.assertEqual(tobytes("r!foo"), data)
     a[0].close()
     ss.close()
     cs.close()
 def pingConnection(self):
     """bit of a hack to trigger a blocking server to get out of the loop, useful at clean shutdowns"""
     try:
         sock=createSocket(connect=self._socketaddr)
         sock.send("!!!!!!!!!!!!!!!!!!!!!")
         sock.close()
     except socket.error:
         pass
 def pingConnection(self):
     """bit of a hack to trigger a blocking server to get out of the loop, useful at clean shutdowns"""
     try:
         sock = createSocket(connect=self._socketaddr)
         sock.send("!!!!!!!!!!!!!!!!!!!!!")
         sock.close()
     except socket.error:
         pass
Example #4
0
 def testCreateBoundSockets(self):
     s = SU.createSocket(bind=('localhost', 0))
     bs = SU.createBroadcastSocket(bind=('localhost', 0))
     self.assertEqual('127.0.0.1', s.getsockname()[0])
     self.assertEqual('127.0.0.1', bs.getsockname()[0])
     s.close()
     bs.close()
     self.assertRaises(ValueError,
                       SU.createSocket,
                       bind=('localhost', 12345),
                       connect=('localhost', 1234))
Example #5
0
 def pingConnection(self):
     """bit of a hack to trigger a blocking server to get out of the loop, useful at clean shutdowns"""
     try:
         sock = createSocket(connect=self._socketaddr)
         if sys.version_info < (3, 0):
             sock.send("!" * 16)
         else:
             sock.send(bytes([1] * 16))
         sock.close()
     except socket.error:
         pass
Example #6
0
 def __init__(self, callbackObject, host, port, timeout=None):
     if os.name=="java":
         raise NotImplementedError("select-based server is not supported for Jython, use the threadpool server instead")
     log.info("starting select/poll socketserver")
     self.sock=None
     self.sock=createSocket(bind=(host,port), timeout=timeout)
     self.clients=[]
     self.callback=callbackObject
     sockaddr=self.sock.getsockname()
     if sockaddr[0].startswith("127."):
         if host is None or host.lower()!="localhost" and not host.startswith("127."):
             log.warn("weird DNS setup: %s resolves to localhost (127.x.x.x)",host)
     host=host or sockaddr[0]
     port=port or sockaddr[1]
     self.locationStr="%s:%d" % (host,port)
Example #7
0
 def testCreateUnboundSockets(self):
     s = SU.createSocket()
     bs = SU.createBroadcastSocket()
     try:
         host, port = s.getsockname()
         self.assertEqual(0, port)
     except socket.error:
         pass
     try:
         if os.name != "java":
             host, port = bs.getsockname()
             self.assertEqual(0, port)
     except socket.error:
         pass
     s.close()
     bs.close()
 def __init__(self, callbackObject, host, port, timeout=None):
     log.info("starting thread pool socketserver")
     self.sock=None
     self.sock=createSocket(bind=(host,port), timeout=timeout)
     self._socketaddr=self.sock.getsockname()
     if self._socketaddr[0].startswith("127."):
         if host is None or host.lower()!="localhost" and not host.startswith("127."):
             log.warn("weird DNS setup: %s resolves to localhost (127.x.x.x)",host)
     host=host or self._socketaddr[0]
     port=port or self._socketaddr[1]
     self.locationStr="%s:%d" % (host,port)
     self.threadpool=set()
     self.workqueue=Queue.Queue()
     for _ in range(Pyro.config.WORKERTHREADS):  #  XXX should be dynamic
         worker=SocketWorker(self, callbackObject)
         self.threadpool.add(worker)
         worker.start()
     log.info("%d worker threads started", len(self.threadpool))
Example #9
0
 def __init__(self, callbackObject, host, port, timeout=None):
     log.info("starting thread pool socketserver")
     self.sock = None
     self.sock = createSocket(bind=(host, port), timeout=timeout)
     self._socketaddr = self.sock.getsockname()
     if self._socketaddr[0].startswith("127."):
         if host is None or host.lower(
         ) != "localhost" and not host.startswith("127."):
             log.warn(
                 "weird DNS setup: %s resolves to localhost (127.x.x.x)",
                 host)
     host = host or self._socketaddr[0]
     port = port or self._socketaddr[1]
     self.locationStr = "%s:%d" % (host, port)
     self.threadpool = ThreadPool(self, callbackObject)
     self.workqueue = queue.Queue()
     for _ in range(Pyro.config.THREADPOOL_MINTHREADS):
         self.threadpool.attemptSpawn()
     log.info("%d worker threads started", len(self.threadpool))