def __enter__(self): # compile the server # NOTE empty filename support is a hack to support # the current test_enet if self.filename: proc = run_process([CLANG_CC, path_from_root('tests', self.filename), '-o', 'server', '-DSOCKK=%d' % self.target_port] + clang_native.get_clang_native_args() + self.args, clang_native.get_clang_native_env(), stdout=PIPE, stderr=PIPE) print('Socket server build: out:', proc.stdout or '', '/ err:', proc.stderr or '') process = Popen([os.path.abspath('server')]) self.processes.append(process) # start the websocket proxy print('running websockify on %d, forward to tcp %d' % (self.listen_port, self.target_port), file=sys.stderr) wsp = websockify.WebSocketProxy(verbose=True, listen_port=self.listen_port, target_host="127.0.0.1", target_port=self.target_port, run_once=True) self.websockify = multiprocessing.Process(target=wsp.start_server) self.websockify.start() self.processes.append(self.websockify) # Make sure both the actual server and the websocket proxy are running for i in range(10): try: if self.do_server_check: server_sock = socket.create_connection(('localhost', self.target_port), timeout=1) server_sock.close() proxy_sock = socket.create_connection(('localhost', self.listen_port), timeout=1) proxy_sock.close() break except IOError: time.sleep(1) else: clean_processes(self.processes) raise Exception('[Websockify failed to start up in a timely manner]') print('[Websockify on process %s]' % str(self.processes[-2:]))
def __enter__(self): import socket, websockify # compile the server # NOTE empty filename support is a hack to support # the current test_enet if self.filename: Popen([ CLANG_CC, path_from_root('tests', self.filename), '-o', 'server', '-DSOCKK=%d' % self.target_port ] + get_clang_native_args() + self.args).communicate() process = Popen([os.path.abspath('server')]) self.pids.append(process.pid) # start the websocket proxy print >> sys.stderr, 'running websockify on %d, forward to tcp %d' % ( self.listen_port, self.target_port) wsp = websockify.WebSocketProxy(verbose=True, listen_port=self.listen_port, target_host="127.0.0.1", target_port=self.target_port, run_once=True) self.websockify = multiprocessing.Process(target=wsp.start_server) self.websockify.start() self.pids.append(self.websockify.pid) print '[Websockify on process %s]' % str(self.pids[-2:])
def vncsocket(host, lport, dport): logger.debug("Spinning up websocket process...") server = websockify.WebSocketProxy(**{ "target_host": host, "target_port": dport, "listen_port": lport }) server.start_server()
import multiprocessing import websockify import socket servers = {} procs = {} for i in range(50): servers[i] = websockify.WebSocketProxy( listen_host='0.0.0.0', listen_port=55900 + i, target_host=socket.getfqdn(), target_port=5900 + i, cert="/etc/pki/libvirt-spice/server-cert.pem", key="/etc/pki/libvirt-spice/server-key.pem") procs[i] = multiprocessing.Process(target=servers[i].start_server) procs[i].start()
def path_from_root(*pathelems): return os.path.join(__rootpath__, *pathelems) sys.path += [path_from_root('tools/'), path_from_root('tools/websockify')] import websockify def websockify_func(wsp): wsp.start_server() client = websockify.WebSocketProxy(verbose=True, listen_port=28785, target_host="127.0.0.1", target_port=28786, run_once=True) client_process = multiprocessing.Process(target=websockify_func, args=(client, )) client_process.start() print 'client on process', client_process.pid server = websockify.WebSocketProxy(verbose=True, listen_port=28780, target_host="127.0.0.1", target_port=28781, run_once=True) server_process = multiprocessing.Process(target=websockify_func, args=(server, )) server_process.start()
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import argparse import authd import websockify if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("-host", help="MKS proxy host (default 'localhost')", default='localhost') parser.add_argument("-port", help="MKS proxy port (default 6090)", type=int, default=6090) parser.add_argument("--web", help="web location") args = parser.parse_args() print('Starting MKS proxy on {0}:{1}'.format(args.host, args.port)) websockify.WebSocketProxy( listen_host=args.host, listen_port=args.port, verbose=True, web=args.web, file_only=True, RequestHandlerClass=authd.AuthdRequestHandler ).start_server()
import multiprocessing import websockify import socket servers = {} procs = {} for i in range(30): servers[i] = websockify.WebSocketProxy(listen_host='0.0.0.0', listen_port=55900 + i, target_host=socket.getfqdn(), target_port=5900 + i) procs[i] = multiprocessing.Process(target=servers[i].start_server) procs[i].start()