Did I find the right examples for you? yes no

All Samples(13)  |  Call(9)  |  Derive(0)  |  Import(4)
Pick a free port choosen by the operating system

        def random_free_port(family=socket.AF_INET, type=socket.SOCK_STREAM):
    """
    Pick a free port choosen by the operating system
    """
    s = socket.socket(family, type)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    try:
        s.bind(("", 0))
        return s.getsockname()[1]
    finally:
        s.close()
        


src/w/s/wstunnel-0.0.3/wstunnel/test/test_toolbox.py   wstunnel(Download)
from wstunnel.factory import load_filter
from wstunnel.filters import DumpFilter
from wstunnel.toolbox import address_to_tuple, tuple_to_address, hex_dump, random_free_port
 
__author__ = 'fabio'
    def _test_random_free_port(self, address, family, type):
        port = random_free_port(family=family, type=type)
        sock = socket.socket(family=family, type=type)
        self.assertRaises(socket.error, sock.connect, (address, port))
 

src/w/s/wstunnel-0.0.3/wstunnel/server.py   wstunnel(Download)
from wstunnel.exception import MappedServiceNotAvailableException
from wstunnel.filters import FilterException
from wstunnel.toolbox import random_free_port
 
__author__ = 'fabio'
    def port(self, value):
        self._port = value if value else random_free_port()
 
    def add_proxy(self, key, ws_proxy):
        logger.debug("Adding {0} as proxy for {1}".format(ws_proxy, key))

src/w/s/wstunnel-0.0.3/wstunnel/test/test_wstunnel.py   wstunnel(Download)
from wstunnel.client import WSTunnelClient, WebSocketProxy
from wstunnel.server import WSTunnelServer
from wstunnel.toolbox import hex_dump, random_free_port
 
 
        clt_tun = WSTunnelClient(family=socket.AF_INET,
                                 io_loop=self.io_loop)
        clt_tun.add_proxy("test", WebSocketProxy(port=0, ws_url="ws://localhost:{0}/test".format(random_free_port())))
        clt_tun.start()
        message = "Hello World!"
    def test_no_server_service(self):
        """
        Tests the server tunnel endpoint behaviour when there's no service to connect
        """
        srv_tun = WSTunnelServer(0, io_loop=self.io_loop, proxies={"/test": ("127.0.0.1", random_free_port())})
        clt_tun = WSTunnelClient(family=socket.AF_INET,
                                 io_loop=self.io_loop)
        clt_tun.add_proxy("test", WebSocketProxy(port=0, ws_url="ws://localhost:{0}/test".format(random_free_port())))
        clt_tun.start()
        self.assertEqual(clt_tun.ws_options, {})

src/w/s/wstunnel-0.0.3/wstunnel/test/test_daemon.py   wstunnel(Download)
    import yaml
    from tornado.ioloop import IOLoop
    from wstunnel.toolbox import random_free_port
    from wstunnel.daemon import WSTunnelClientDaemon, WSTunnelServerDaemon, Daemon, wstuncltd, wstunsrvd
 
            self.tun_conf["logging"]["handlers"]["file_handler"]["filename"] = self.log_file
            self.tun_conf["pid_file"] = self.pid_file
            self.tun_conf["proxies"]["/test"]["port"] = random_free_port()
 
            IOLoop.instance().start = lambda: 0
            self.tun_conf["logging"]["handlers"]["file_handler"]["filename"] = self.log_file
            self.tun_conf["pid_file"] = self.pid_file
            self.tun_conf["listen"] = random_free_port()
 
            IOLoop.instance().start = lambda: 0
            self.tun_conf["logging"]["handlers"]["file_handler"]["filename"] = self.log_file
            self.tun_conf["pid_file"] = self.pid_file
            self.tun_conf["proxies"]["/test"]["port"] = random_free_port()
            self.tun_conf["ws_url"] = "wss://localhost:9000/"
 
            self.tun_conf["logging"]["handlers"]["file_handler"]["filename"] = self.log_file
            self.tun_conf["pid_file"] = self.pid_file
            self.tun_conf["listen"] = random_free_port()
            self.tun_conf["ssl"] = True
            self.tun_conf["ssl_options"].update({"certfile": os.path.join(fixture, "localhost.pem"),