def call_backend(filename):
    # Connect to the matlab backend.
    blub = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    blub.connect(('localhost', 60000))
    # Send query.
    ch = ConnectionHandler(blub)
    ch.send(filename)
    return ch.recv()
def call_backend(filename):
    # Connect to the matlab backend.
    blub = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    blub.connect(('localhost', 60000))
    # Send query.
    ch = ConnectionHandler(blub)
    ch.send(filename)
    return ch.recv()
Esempio n. 3
0
def main(stdscr, argv):
    usage = "Usage: client (-h | --host) <host-address> (-p | --port) <port>"

    logging.basicConfig(filename="client.log", level = logging.NOTSET)
    logging.info("Initialising curses interface...")
    stdscr.clear()
    output = curses.newwin(curses.LINES - 3, curses.COLS, 0, 0)
    field = curses.newwin(2, curses.COLS, curses.LINES - 2, 0)
    output.refresh()
    field.refresh()

    curses.start_color()
    curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_YELLOW)
    curses.echo()
    stdscr.bkgd(curses.color_pair(1))
    field.bkgd(curses.color_pair(2))
    logging.info("Finished initialising curses")

    logging.info("Parsing arguments...")
    try:
        opts, args = getopt.getopt(argv, "h:p:", ["host", "port"])
    except getopt.GetoptError as err:
        output.addstr(usage)
        sys.exit(2)

    host = "127.0.0.1"
    port = "2002"

    for o, a in opts:
        if o in ("-h", "--host"):
            host = a
        elif o in ("-p", "--port"):
            port = a
        else:
            logging.warning("Bad arguments, using default of " + host + ":" + str(port))

    logging.info("Finished parsing arguments")
    logging.info("Connecting...")
    logger = logging.getLogger(__name__)
    output.addstr("Connecting to host " + host + ":" + port + "...")
    output.refresh()
    conn = ConnectionHandler(host = host, port = int(port), logger = logger, ssl = False)
    dispatcher = Dispatcher()

    conn.connect(output)
    logging.info("Connected")
    logging.info("Starting threads...")
    r = threading.Thread(target=Receiver, args = (conn, dispatcher, output))
    r.daemon = True
    r.start()
    s = threading.Thread(target=Sender, args = (conn, field))
    s.daemon = True
    s.start()
    logging.info("Started threads")

    while(True):
        time.sleep(1)
Esempio n. 4
0
	def spawn_connection(self, rport):
		lport = randint(1024, 65535)
		conn = Connection(self.lhost, self.rhost, lport, rport)

		conn_handler = ConnectionHandler(conn, self.outp_queue, self.res_queue)
		self.conns[conn] = conn_handler

		logger.debug("Starting new handler thread for connection: %s" % (conn))
		conn_handler.start()
Esempio n. 5
0
def AddHundred(num):
    # Connect to the matlab backend.
    blub = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    blub.connect(('localhost', 60000))

    # Send query.
    ch = ConnectionHandler(blub)
    ch.send(num)

    # Display the result.
    return ch.recv()
def AddHundred(num):
    # Connect to the matlab backend.
    blub = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    blub.connect(('localhost', 60000))

    # Send query.
    ch = ConnectionHandler(blub)
    ch.send(num)

    # Display the result.
    return ch.recv()
def AddHundred(num):
    # Connect to the matlab backend.
    blub = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    blub.connect(('localhost', 60000))

    # Send query.
    ch = ConnectionHandler(blub)
    ch.send(num)

    # Display the result.
    json_list = ch.recv()
    print json_list
    return json.dumps(json_list, separators=(',', ':'))
def AddHundred(num):
    # Connect to the matlab backend.
    blub = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    blub.connect(('localhost', 60000))

    # Send query.
    ch = ConnectionHandler(blub)
    ch.send(num)

    # Display the result.
    json_list = ch.recv()
    print json_list
    return json.dumps(json_list, separators=(',',':'))
    def handle(self):
        connectionHandler = ConnectionHandler(self.request)
        data = connectionHandler.recv()

        start = time.time()

        # Run classification script
        ranking = mlab.server_classification(data, self.server.weight_matrix, self.server.net)

        connectionHandler.send(str(gen_json(ranking)))

        t = time.time() - start

        print('Finished processing. Required %f seconds.' % t)
  def handle(self):
    connectionHandler = ConnectionHandler(self.request)
    data = connectionHandler.recv()

    start = time.time()

    # TODO(James): Add your classification code here...
    ranking = mlab.server_classification(data, self.server.weight_matrix, self.server.net)
    print('Ranking:')
    print(ranking)

    print(int(ranking[0]))
    connectionHandler.send(str(int(ranking[0])))

    # Use model via use_model.
    #output = mlab.use_model(self.server.model, int(data))
    #print('Output %d' % output)
    #connectionHandler.send('%d' % output)

    t = time.time() - start

    print('Finished processing. Required %f seconds.' % t)
	def __init__(self):
		self.server = ConnectionHandler()
		self.musicdb = MusicDB()
		self.threads = [self.server, self.musicdb]
Esempio n. 12
0
# Run this after launching the server. Server should say (1 + 100) = 101.

import socket
from ConnectionHandler import ConnectionHandler

# Connect to the matlab backend.
blub = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
blub.connect(('localhost', 60000))

# Send query.
ch = ConnectionHandler(blub)
ch.send('image_00001.jpg')
print 'Received %s' % ch.recv()
Esempio n. 13
0
	def spawn_connection(self, rport):
		lport = random.randint(1024, 65535)
		conn = Connection(self.lhost, self.rhost, lport, rport)
		conn_handler = ConnectionHandler(conn, self.outp_queue, self.res_queue)
		self.conns[conn] = conn_handler
		conn_handler.start()