def main(): parser = ArgumentParser(description="A simple chat application") parser.add_argument( "--server", help="Run server app or client", action="store_true" ) parser.add_argument("--verboose", action="store_true") args = parser.parse_args() if args.server: start_server(args.verboose) else: start_client()
class Manager: ##Screen width, height = 950, 600 size = width, height screen = pygame.display.set_mode(size) pygame.display.set_caption("SpaceInvaders") #InputManager inputManager = InputManager() #Introduction state state = StateGameIntro(0, screen, inputManager) client = start_client() #Game started check game_started = False #Main Loop def _run(self): self.gameOn = True while self.gameOn: dt = fpsClock.tick(30) run() #Inputs self.inputManager.update() if self.game_started == False: if self.state.start == 100: self.set_state(StateGame(self.screen, self.inputManager, self.client)) self.game_started = True #Updates self.update(dt) #Renders, put in the screen self.render() #Update def update(self, dt): #state updates new_state = self.state.update(dt) if (new_state == 0): return def set_state(self, state): self.state.destroy() self.state = state #Render def render(self): #state renders self.state.render() #updates the display pygame.display.update()
def main(): parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument('--server_address', metavar=('address', 'port'), type=str, nargs=2, help='address of the werbserver') args = parser.parse_args() isserver = False serverhost = "localhost" serverport = 9999 if args.server_address: isserver = True serverhost = args.server_address[0] serverport = args.server_address[1] #config = ConfigParser.ConfigParser() #config.readfp(open('global.ini')) RATE = 3000 #config.getint('global', 'BITRATE') CHUNKSIZE = 1000 #config.getint('global', 'CHUNKSIZE') CHANNELS = 3000 #config.getint('global', 'CHANNELS') BUFFER_TIME = 2 #maybe make this a command line arg GAIN = 1000 produce_sound = True network_is_active = True #------------------------------ #COMMUNICATION SHIT GOES HERE #WHEN A MESSAGE IS RECEIVED, IT SHOULD #CONTAIN (f1, f2, T, when_it_starts) #simulating parameters f1 = 2000 f2 = 4000 T = 0.5 start_T = 1 #------------------------------ parsed = {'f1': f1, 'f2': f2, 'T': T, 'start_T': start_T} sound_processor = sp.SoundProcessor(rate=RATE, channels=CHANNELS, chunksize=CHUNKSIZE) chirp_params = { 'f1': parsed['f1'], 'f2': parsed['f2'], 'T': parsed['T'], 'gain': GAIN } detector = sp.SoundDetector(RATE, win_type='hann') detector.make_template(chirp_params, mode='linear_chirp') if (isserver): print("starting server") p = Process(target=server.start_server) p.start() p.join() time.sleep(1) input('Press Enter to start calling: ') client.start_client(serverhost, int(serverport), start=isserver)
def test_parse_request_raise_error(http_request, response): """Tests all error types from the server.""" from client import start_client assert start_client(http_request) == response
#!/bin/python from client import start_client from configManager import ConfigManager if __name__ == '__main__': cm = ConfigManager() mysql_db_server_ip = cm.getConfigValue('mysql_db_server_ip') mysql_user = cm.getConfigValue('mysql_user') mysql_password = cm.getConfigValue('mysql_password') mysql_db_name = cm.getConfigValue('mysql_db_name') REDIS_HOST = cm.getConfigValue('REDIS_HOST') REDIS_PORT = cm.getConfigValue('REDIS_PORT') REDIS_db = cm.getConfigValue('REDIS_db') if mysql_db_server_ip is None or mysql_db_server_ip == '': raise Exception('mysql_db_server_ip is not configured') if mysql_user is None or mysql_db_server_ip == '': raise Exception('mysql_user is not configured') if mysql_password is None or mysql_db_server_ip == '': raise Exception('mysql_password is not configured') if mysql_db_name is None or mysql_db_server_ip == '': raise Exception('mysql_db_name is not configured') if REDIS_HOST is None or mysql_db_server_ip == '': raise Exception('REDIS_HOST is not configured') if REDIS_PORT is None or mysql_db_server_ip == '': raise Exception('REDIS_PORT is not configured') if REDIS_db is None or mysql_db_server_ip == '': raise Exception('REDIS_db is not configured') start_client(mysql_db_server_ip, mysql_user, mysql_password, mysql_db_name, REDIS_HOST, REDIS_PORT, REDIS_db)
from flask import Flask, jsonify, request from flask_api import status from server import app from classes.iHabit_system import iHabit_system from client import start_client, pickle_update from validation.form_validation import validate_signup, validate_login, validate_habit_name, validate_password, validate_email system = start_client() # USER SERVICES @app.route("/user", methods=["GET"]) def get_user(): user_id = int(request.args.get('user_id')) user = system.get_user(user_id) if (user != -1): return { 'username': user.username, 'email': user.email }, status.HTTP_200_OK @app.route("/user", methods=["POST"]) def add_user(): data = request.get_json() username = data["username"] password = data["password"] email = data["email"] if validate_signup(username, password, email) == 0: if system.username_available(username) == 0: user_id = system.add_user(username, password, email)
import client import sys appication_id = sys.argv[1] if len(sys.argv) == 2 else "client" client = client.ClientLogic(appication_id) client.start_client()
def testUnknownResponseCode(self): serverProcess = Process(target=start_server) serverProcess.start() with self.assertRaises(UnknownCode): start_client('127.0.0.1', server_port, 'Unknown') serverProcess.terminate()
def testConnectError(self): with self.assertRaises(Exception): start_client('132.0.0.0', 21)
def testUnknownServer(self): with self.assertRaises(ValueError): start_client(156, 'asa')
logging.basicConfig(filename='logs/nchat.log', level=logging.DEBUG, format=log_format, datefmt=log_dateformat) # If DEBUG is set to False (default) all logging goes to a file else: logging.basicConfig(filename='logs/nchat.log', level=logging.INFO, format=log_format, datefmt=log_dateformat) logging.info('Started logging') logging.info('Started main chat program') logging.info('Parsing server config...') # Get information then start the server serverInfo = Config.ServerInfo() logging.info('Config parsed successfully') logging.info('Starting server on {0}:{1}'.format(serverInfo.HOST, serverInfo.PORT)) # Start client and server ts = threadedServer sthread = ts.start_server(serverInfo) logging.info('Server started on {0}:{1}'.format(serverInfo.HOST, serverInfo.PORT)) logging.info('Starting client...') client.start_client(serverInfo, ts, sthread)
KEY_STATES['RIGHT'] = True @window.event def on_key_release(symbol, modifiers): if symbol == key.UP: KEY_STATES['UP'] = False elif symbol == key.DOWN: KEY_STATES['DOWN'] = False elif symbol == key.LEFT: KEY_STATES['LEFT'] = False elif symbol == key.RIGHT: KEY_STATES['RIGHT'] = False @window.event def on_draw(): for player in PLAYERS.values(): player.draw() def data_received(data): name = data['NAME'] if name not in PLAYERS.keys(): print('player {} added'.format(name)) if PLAYERS.get(name) != data: print(data) PLAYERS[name] = data LOOP.call_later(NETWORK_WAIT, send_data) start_client(data_received_callback=data_received)