def start_server(self, ip): """ :param ip: :return: """ server = ServerThread(ip) server.start()
def start_server(self): self.log("Trying to start server thread ...") self.server = ServerThread(port=int(self.txt_port.text, 10)) self.logbox.connect(self.server, SIGNAL("log(QString)"), self.log) self.logbox.connect(self.server, SIGNAL("command(QString)"), self.command) self.server.set_taskview(self) self.server.start()
def run(self): while (self.runningThread): if (self.beacon_thread != None and not self.beacon_thread.is_alive()): print("Restart beacon thread") self.logFile.saveWithDate("Restart beacon thread") self.beacon_thread = ServerBeaconThread( threadID=self.threadID + 1, host_ip=self.host_ip, broadcast_ip=self.broadcast_ip, negotiation_port=self.negotiation_port, sleepDuration=1.9, logFile=self.logFile) self.beacon_thread.start() if (self.server_thread != None and not self.server_thread.is_alive()): print("Restart server thread") self.logFile.saveWithDate("Restart server thread") self.server_thread = ServerThread( threadID=self.threadID + 2, address=self.server_address.asTuple(), carMap=self.carMap, logFile=self.logFile) self.server_thread.start() if (self.forwarding_thread != None and not self.forwarding_thread.is_alive()): print("Restart forwarding thread") self.logFile.saveWithDate("Restart forwarding thread") self.forwarding_thread = Forward2CarThread( threadID=self.threadID + 3, car_communication_port=self.car_communication_port, carMap=self.carMap, period=1.0, logFile=self.logFile) self.forwarding_thread.start() if (self.carSubscriber_thread != None and not self.carSubscriber_thread.is_alive()): print("Restart carSubscriber thread") self.logFile.saveWithDate("Restart carSubscriber thread") self.carSubscriber_thread = Listen4CarSubscriberThread( threadID=self.threadID + 4, host_ip=self.host_ip, car_subscription_port=self.car_subscription_port, carMap=self.carMap, logFile=self.logFile) self.carSubscriber_thread.start() if (self.server_address.ip == '' and self.server_address.port == -1): self.NegotiateServer() time.sleep(1.1)
def main_loop(self): client = Client() t = ServerThread(client) t.start() while True: data = raw_input('>>> ') if data == 'exit': break else: if data == 'exit lego': data = 'exit' client.send(data) client.close() t.exit_server = True t.join()
def main(): parser = argparse.ArgumentParser(description='LP options') parser.add_argument('-logging_dir', type=str, default="logs", help="Logging directory") args = parser.parse_args() server_thread = ServerThread(args.logging_dir) server_thread.start() menu_loop = menu.Menu() try: menu_loop.cmdloop() except KeyboardInterrupt as e: pass server_thread.should_stop = True
def listening_thread(stop_event): sock = socket.socket() sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind(('', 1337)) sock.listen(5) while not stop_event.is_set(): try: conn, addr = sock.accept() except KeyboardInterrupt as e: raise ValueError("Can't accept new connection") try: server_thread = ServerThread(1, conn) server_thread.set_caller(taskmasterd) server_thread.run() except: #print ("Error: unable to start thread") conn.close()
def standalone_server(bin_prefix, tmp_path): server = ServerThread(bin_prefix, str(tmp_path)) server.start() wait_result = server.wait() if wait_result is not None: with open(os.path.join(server.log_dir, 'server', 'stdout.txt'), 'r') as f: print >> sys.stderr, f.read() with open(os.path.join(server.log_dir, 'server', 'stderr.txt'), 'r') as f: print >> sys.stderr, f.read() pytest.fail('Server died unexpectedly with code {code}'.format( code=server._proc.returncode), pytrace=False) yield server server.stop()
def launch_server(server_id, entities_threads, network_data): # unpack dictionaries servers_data = network_data["servers_data"] routers_data = network_data["routers_data"] routers_threads = entities_threads["routers_threads"] servers_threads = entities_threads["servers_threads"] server_data = servers_data[server_id] default_gateway = server_data["gateway_ip"] arp_table_mac = data.server_arp_table_generator(default_gateway, routers_data) # find the id of the router to which the client will connect for router, router_data in routers_data.items(): if (router_data["server_side"]["ip_address"] == default_gateway): router_id = router break router_thread = routers_threads[router_id] init_params = { "servers_threads": servers_threads, "arp_table_mac": arp_table_mac, "router_id": router_id, "router_thread": router_thread, "server_data": server_data, "server_id": server_id, } server_thread = ServerThread(init_params) servers_threads[server_id] = server_thread server_thread.start()
def test_validation_2_3(self): """ test_validation_3 Filter 2 against filter_validation 3 """ saved = SavedFilter(self.lc, 2) # Get loan list response = self.lc.session.get('/filter_validation', query={'id': 3}) json_response = response.json() self.loan_list = json_response['loanFractions'] # Validate, should fail on 'exclude_invested' try: saved.validate(self.loan_list) assert False, 'Test should fail on grade' except FilterValidationError as e: print e.criteria self.assertTrue(matches('grade', e.criteria)) if __name__ == '__main__': # Start the web-server in a background thread http = ServerThread() http.start() # Run tests unittest.main() # Stop threads http.stop()
if not q.empty(): r = q.get() if isinstance(r, MailDataFrame): print(r.data) else: for i in range(2): if r[-i] in ["\r", "\n"]: r = r[:-i] print(r) HOST = '127.0.0.1' SERVPORT = 42069 DESTPORT = 25 BACKLOG = 5 msg_q = Queue() log_q = Queue() client_thread = ClientThread((HOST, DESTPORT), msg_q, log_q, daemon=True) client_thread.start() log = Thread(target=logger, args=(log_q, ), daemon=True) log.start() with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.bind((HOST, SERVPORT)) i = 0 while True: s.listen(BACKLOG) cl_skt, addr = s.accept() t = ServerThread(cl_skt, msg_q, log_q, daemon=True) t.start() i = i + 1
tzco = 80 # Initial values for data calculated by the model tr = 20 tpco = 75 # Initial flow fcob = 40 # Data dict we'll be modifying and sending data = {'Tpcob': tpco, 'Fcob': fcob, 'Tr': tr} lock = Lock() host = 'localhost' port = 50009 server = ServerThread(data, host, port) server.start() # Used for local logging and visualization, probably will be deleted later so we don't get a MemoryError because # these get too big. Another option would be to serialize them and save to file but who's got time for that? time_vector = [] tpco_vector = [] tr_vector = [] ntp = NTPClient() t = t_0 = ntp.request('1.pl.pool.ntp.org').tx_time last_error = 0 error_integral = 0 while True: try: to = request_data(energy_provider[0], energy_provider[1], 'To')
from threading import Thread from server import ServerThread import socket import sys port = sys.argv[1] path = sys.argv[2] address = '127.0.0.1' socket_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) socket_server.bind((address, int(port))) socket_server.listen() while (True): print("Esperando conexão ....") conn, addr = socket_server.accept() newThread = ServerThread(address, port, conn, addr, path) newThread.start()
def NegotiateServer(self): ''' Function that decides which simulated GPS starts the server. ''' print("Negotiation start!") s = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM) s.bind(('', self.negotiation_port)) s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) randTime = 10 * self.max_wait_time_for_server * random.random() wait_time = 2 + math.floor(randTime) / 100 print("Waiting " + str(wait_time) + " seconds for server") t = time.time() server = [] try: # listen for server broadcast s.settimeout(wait_time) data, SERVER_IP = s.recvfrom(1500, 0) # server beacon received s.close() print("Server started on " + str((SERVER_IP[0]))) # store server info self.server_address.ip = str(SERVER_IP[0]) self.server_address.port = self.subscription_port except KeyboardInterrupt: print('KeyboardInterrupt') except Exception as e: print("No response, starting server here", e) s.sendto(bytes(self.host_ip, "UTF-8"), (self.broadcast_ip, self.negotiation_port)) s.close() self.stopAllThread() self.server_address.ip = self.host_ip self.server_address.port = self.subscription_port if (self.logFile != None): log_message = 'NegotiateServer- server address %s' % str( self.server_address) self.logFile.saveWithDate(log_message) self.carMap = Data4CarMap(256) # thread responsible for broadcasting itself as the server self.beacon_thread = ServerBeaconThread( threadID=self.threadID + 1, host_ip=self.host_ip, broadcast_ip=self.broadcast_ip, negotiation_port=self.negotiation_port, sleepDuration=1.9, logFile=self.logFile) self.beacon_thread.start() # thread responsible for collecting GPS data from clients self.server_thread = ServerThread( threadID=self.threadID + 2, address=self.server_address.asTuple(), carMap=self.carMap, logFile=self.logFile) self.server_thread.start() # thread responsible for sending GPS data to each registered vehicle self.forwarding_thread = Forward2CarThread( threadID=self.threadID + 3, car_communication_port=self.car_communication_port, carMap=self.carMap, period=1.0, logFile=self.logFile) self.forwarding_thread.start() # thread responsible for registering vehicles self.carSubscriber_thread = Listen4CarSubscriberThread( threadID=self.threadID + 4, host_ip=self.host_ip, car_subscription_port=self.car_subscription_port, carMap=self.carMap, logFile=self.logFile) self.carSubscriber_thread.start() print(str(time.time() - t) + " seconds elapsed")