示例#1
0
    def main(self):

        #Open receiving end
        recv_socket = connection.Server(self.HOST, self.PORT_RECV)
        recv_socket.connect()

        #Open sending end
        send_socket = connection.Server(self.HOST, self.PORT_SEND)
        send_socket.connect()
        send_socket.accept()

        #Opening threads
        stt_thread = Thread(target=self.speechToText, args=(send_socket, ))
        stt_thread.start()

        try:
            while True:
                self.log.info("\nListening for incoming connections...")

                recv_socket.accept()

                #Open a new thread for each incoming connection
                newConnThread = Thread(target=self.receive_audio,
                                       args=(recv_socket, ))
                newConnThread.start()

        except KeyboardInterrupt as e:
            raise e
        except Exception as e:
            raise e
        finally:
            self.log.debug('\nCLOSING SOCKETS')
            recv_socket.destroy()
            send_socket.destroy()
            self.AUDIO_QUEUE.put(None)
示例#2
0
    def start(self):
        server_listen = connection.Server(self.listen_ip, self.listen_port)
        while not self.shutdown:
            response = {}
            command = server_listen.listen()
            data = command.recv(2048).decode()
            try:
                jdata = json.loads(data.replace("'", '"'))
                query = jdata['query']
                execute = True
            except:
                self.log.error("cannot understand control command: %s" % data)
                execute = False
            if execute:
                self.log.info("executing query %s" % query)

                if query == "getshares":
                    response = self.get_shares()

                elif query == "cleanshares":
                    response = self.clean_shares()

                elif query == "getinfo":
                    response = json.dumps(str(self.get_info()),
                                          ensure_ascii=True)

                elif query == 'setpool':
                    host = jdata['host'] if 'host' in jdata else None
                    port = jdata['port'] if 'port' in jdata else None
                    user = jdata['user'] if 'user' in jdata else None
                    passw = jdata['passw'] if 'passw' in jdata else None
                    response = str({"error": False})
                    if host and port and user and passw:
                        self.set_pool(host, port, user=user, passw=passw)
                    elif host and port and user:
                        self.set_pool(host, port, user=user)
                    elif host and port:
                        self.set_pool(host, port)
                    else:
                        response = str({"error": True})

                    self.reconnect_all()

                elif query == 'setbackup':
                    pass

                else:
                    response = str({"error": True})

                command.sendall(response.encode())
            else:
                command.sendall(str({"error": True}).encode())

            command.shutdown(0)
            command.close()
            time.sleep(0.5)
示例#3
0
    def comm_confirmation(self):
        """Receieves confirmation of action on Actuator and logs total time
		
		Opens a server connection to the Actuator in order to receive
		confirmation on action on its side. Gets the time of receival of the
		message and uses along with the time in which audio stopped being sent
		to get the total roundtrip time
		"""

        self.log.debug('=================== \
			Starting thread comm_confirmation ===================')
        self.act = connection.Server('', 5008)
        self.act.connect()
        self.act.accept()

        count = 0

        while True:

            #Finishes if flag is set
            if self.finish:
                break

            #Receives data from Actuator
            command = self.act.receive_message()

            #Stores the time of message arrival
            arrival = timeit.default_timer()

            #Checks if connection was not closed on the other side
            if command != None:
                dispatch_time = self.timeQueue.get()

                #Checks for keyboard interruption on main thread
                if dispatch_time == None:
                    break

                self.log.info("command received:  " + command)
                parts = command.split('-')
                if int(parts[1]) != count:
                    self.log.debug('Received command number ' + parts[1] +\
                     ' but waiting for command number ' + str(count) +\
                     "'s status")

                #Roundtrip time
                time_dif = arrival - dispatch_time

                self.log.info("Command number " + str(count) +\
                 " execution time:  " + str(time_dif))
                count += 1
            else:
                self.log.debug('Actuator connection closed on the other side')
                break
示例#4
0
t.start()

# Set and start control thread
controller = control.Control(proxydb=proxies, sharestats=shares)
controller.listen_ip = args.control
controller.listen_port = args.control_port
controller.poolmap['pool'] = args.pool
controller.poolmap['port'] = args.port
controller.poolmap['user'] = args.username
controller.poolmap['pass'] = args.password
t = threading.Thread(target=controller.start, args=[])
t.daemon = True
t.start()

# Start listening for incoming connections
server_listen = connection.Server(args.listen, args.listen_port)


while not shutdown:
    # Wait for client connection
    miner = server_listen.listen()
    pool_connection = connection.Client(controller.poolmap['pool'], controller.poolmap['port'])
    pool = pool_connection.connect()
    proxy = Proxy.Proxy(pool, sharestats=shares)
    proxy.set_auth(controller.poolmap['user'], controller.poolmap['pass'])
    proxy.add_miner(miner)
    t = threading.Thread(target=proxy.start, args=[])
    t.daemon = True
    t.start()
    proxies.add_proxy(proxy, t)
示例#5
0
pygame.mixer.quit()

screen = pygame.display.set_mode((1280, 720))  #畫面大小
menu_font = pygame.font.Font('msjh.ttc', 40)  #字體

Game_title = menu_font.render('手 速 遊 戲', True, (255, 255, 255))
options = [
    Option("開始", (600, 200)),
    Option("排行榜", (580, 250)),
    Option("離開", (600, 300))
]

win_text = menu_font.render('WIN!', True, (0, 0, 0))

me, enemy = define_players()
server = connection.Server(MY_SERVER_HOST, MY_SERVER_PORT)

Playing = False
Movie_stop = False
GAME_OVER = False

clock = pygame.time.Clock()

movie = pygame.movie.Movie('second.mpg')
movie_screen = pygame.Surface(movie.get_size()).convert()
movie.set_display(movie_screen)

timer = [0.0]
dt = 1.0

cost_second = [0.0]
示例#6
0
import socket
import controller, connection

server = connection.Server()
conn = server.startServer()

app = controller.Controller(conn)
app.startPlayer()

conn.close()
print('quit')
示例#7
0
 def run(self):
     self.info('started, test range {0}:{1}'.format(self.start_test,
                                                    self.end_test))
     self.server = connection.Server(self.port, self, self.is_tls)
     self.server.start()