Exemple #1
0
def connect_to_google(payload):
    # eg. payload = f'GET / HTTP/1.0\r\nHost: {host}\r\n\r\n'
    proxy_data = b""  # bytestring!
    try:
        # define address info, payload, and buffer size
        host = 'www.google.com'
        port = 80
        buffer_size = 4096
        # make the socket, get the IP, and connect
        s = client.create_tcp_socket()
        remote_ip = client.get_remote_ip(host)
        s.connect((remote_ip, port))
        print(f'Socket connected to {host} on IP {remote_ip}')
        # send the data and shutdown
        client.send_data(s, payload)
        s.shutdown(socket.SHUT_WR)
        # continue accepting data until no more is left
        while True:
            data = s.recv(buffer_size)
            if not data:
                #print(data)
                break
            proxy_data += data
        print("Data from", host, "received")
        #print(proxy_data)
    except Exception as e:
        print(e)
    finally:
        s.close()  # always close at the end!
    return proxy_data
def main():
    try:
        # define address info, payload, and buffer size
        host = ''
        port = 8001
        buffer_size = 4096

        # make the socket, get the ip, and connect
        s = create_tcp_socket()

        remote_ip = get_remote_ip(host)

        s.connect((remote_ip, port))
        print(f'Socket Connected to {host} on ip {remote_ip}')

        # send the data and shutdown
        payload = f'GET / HTTP/1.0\r\nHost: www.google.com\r\n\r\n'
        send_data(s, payload)
        s.shutdown(socket.SHUT_WR)

        # continue accepting data until no more left
        full_data = b""
        while True:
            data = s.recv(buffer_size)
            if not data or (len(data) < 5 and data.decode() == 'DONE'):
                break
            full_data += data
        print(full_data)
    except Exception as e:
        print(e)
    finally:
        # always close at the end!
        s.close()
def main():
    try:
        # Should match what proxy_server.py is expecting
        host = ""
        port = 8001
        # Should go thru the proxy to google and back
        payload = f'GET / HTTP/1.0\r\nHost: {host}\r\n\r\n'
        buffer_size = 4096
        # make the socket, get the IP, and connect
        s = client.create_tcp_socket()
        remote_ip = client.get_remote_ip(host)
        s.connect((remote_ip, port))
        print(f'Socket connected to {host} on IP {remote_ip}')
        # send the data and shutdown
        client.send_data(s, payload)
        s.shutdown(socket.SHUT_WR)
        # continue accepting data until no more is left
        full_data = b""  # bytestring!
        while True:
            # "receive" and specify buffer size (amount of data to get)
            data = s.recv(buffer_size)
            if not data:
                #print(data)
                break
            full_data += data
        print(full_data[:200], "...")
    except Exception as e:
        print(e)
    finally:
        # always close at the end!
        s.close()
Exemple #4
0
def hello_world():
    if request.method == 'POST':
        temperature = request.form["temperature"]
        humidity = request.form["humidity"]
        username = request.form["username"]
        # print('name', username)
        # print('温度', temperature)
        # print('湿度', humidity)
        client.send_data("[{},{},{}]".format(username, temperature, humidity))
    return render_template("index.html")
Exemple #5
0
def main():
    # domain, problem, IPAdr, port = configure_planner()
    maze_pb = int(
        input('Wich problem file should we use ?'
              ' (0,1,2,3 ou 4) :'))

    # Loading PDDL datas
    problem_file = 'pddl/problem-maze{}.pddl'.format(maze_pb)
    domprob = get_domprob('pddl/domain-maze.pddl', problem_file)
    goal = convert_to_tuple_set(domprob.goals())
    initial_state = convert_to_tuple_set(domprob.initialstate())
    op_list = list(domprob.operators())

    # Init bitvectors
    nb_robots = get_nb_robots(initial_state)
    width, height = get_width_and_height(problem_file)
    set_robot_list(initial_state)
    init_bv = convert_to_bv(initial_state, nb_robots, width, height)
    goal_bv = convert_to_bv(goal, nb_robots, width, height)
    root = create_root(init_bv)
    params = (root, goal_bv, init_bv, domprob, nb_robots, width, height)

    # Creating and sending config list
    conf_list = build_config_list(initial_state, op_list, domprob)
    print('[PLANNER]Sending conf list')
    send_object(conf_list)

    # Searching for a path
    path = search(dijkstra_search, params)

    if path is None:
        print('No path found.')
    else:
        # Parsing datas
        goal_str = goals_to_string(goal)
        robots_str = robots_coord_to_string(initial_state)
        path_str = path_to_string(path, get_robot_list(initial_state),
                                  width * height, width)
        message = build_message(goal_str, "", robots_str, path_str)
        # Sending path to the simulator
        print('[PLANNER]Sending path')
        send_object(path)
        print('[PLANNER]Sending datas')
        send_data(message)
def sendToGoogle(conn):
    try:
        # recieve data, wait a bit, then send it back
        payload = conn.recv(BUFFER_SIZE).decode('utf-8')
        # define address info, payload, and buffer size
        host = 'www.google.com'
        port = 80

        # make the socket, get the ip, and connect
        s = create_tcp_socket()

        s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

        remote_ip = get_remote_ip(host)

        s.connect((remote_ip, port))

        send_data(s, payload)
        s.shutdown(socket.SHUT_WR)

        # continue accepting data until no more left
        full_data = b""
        while True:
            data = s.recv(BUFFER_SIZE)
            if not data:
                break
            full_data += data
    except Exception as e:
        print(e)
    finally:
        # always close at the end!
        s.close()
        conn.sendall(full_data)
        conn.sendall("DONE".encode())
        conn.close()
        return full_data
Exemple #7
0
import client
from time import sleep

if __name__ == '__main__':
    while True:
        your_key = "some_key"
        your_data = 22
        client.send_data(your_data, your_key)
        sleep(60)
Exemple #8
0
def sendDistance(s, distance):
    client.send_data(s, distance)
Exemple #9
0
    main_path = os.path.dirname(sys.path[0].strip())
    cron_status = main_path + "/tmp/monitor_cron.status"
    cron_data = main_path +"/tmp/monitor_info.dat"
    
    with open(cron_data) as f:
        data = f.read()
    with open(cron_status,'r') as s_f:
        status = s_f.read()
    if len(status) == 0:
        try:
            f  = open(cron_status,'w')
            f.write('0')
            f.close()
        except Exception,e:
            log.log(e)
        sys.exit(1)
    if int(status.strip()) is not 0 or not data.__len__():
        log.log('Not collect data')
        return 0
   
    if client.send_data(data) is 0:
        try:
            f = open(cron_data,'w')
            f.write('')
            f.close() 
        except Exception,e:
            log.log(e)
            sys.exit(1)


import client

#elephant flows

# num_elephant_flows = 60
num_elephant_flows = 1
# no_of_bytes_to_send = 1370
no_of_bytes_to_send = 10
total_exp_time = 600
total_exp_time = 600
elecphant_flow_time = 1
total_packets_sent = 0
for SOURCE_PORT in range(7011, 7011 + num_elephant_flows):
    print("Sending using Source_port : ", SOURCE_PORT)
    total_packets_sent += client.send_data(elecphant_flow_time,
                                           no_of_bytes_to_send, SOURCE_PORT)
print("total_packets_sent = ", total_packets_sent)
Exemple #11
0
    def run(self):
        global total_packets_sent_thread1
        global total_packets_sent_thread2
        global end_t2
        global total_packets_sent_thread3
        global total_packets_sent_thread4

        threadID = self.threadID
        UDP_SERVER = str(sys.argv[1])

        if threadID == 0:
            # num_elephant_flows = 60
            time_thread1 = datetime.now()
            no_of_bytes_to_send = 1370
            elephant_flow_time = 10
            num_elephant_flows = int(total_exp_time / elephant_flow_time)
            total_packets_sent_elephant = 0
            for SOURCE_PORT in range(7000, 7000 + num_elephant_flows):
                # print ("Sending elephant_flow using Source_port : ",SOURCE_PORT)
                # total_packets_sent_elephant += client.send_data(elecphant_flow_time,no_of_bytes_to_send,SOURCE_PORT)
                total_packets_sent_thread1 += client.send_data(
                    elephant_flow_time, no_of_bytes_to_send, SOURCE_PORT,
                    UDP_SERVER)
            print("total_packets_sent_thread1 = ", total_packets_sent_thread1)
            print("total time in thread1 = ",
                  (datetime.now() - time_thread1).total_seconds())
            print("ending and setting t2")
            end_t2 = 59

            # print ("total_packets_sent_elephant = ",total_packets_sent_elephant)
        # if threadID in range(1,11):
        if threadID == 1:
            time_thread2 = datetime.now()
            num_mouse_flows = 450
            no_of_bytes_to_send = 10
            mouse_flow_time = 0.1
            total_packets_sent_mouse = 0
            upto = 50000 + (num_mouse_flows * 100)
            for SOURCE_PORT in range(50000, upto):
                if SOURCE_PORT > 50449:
                    SOURCE_PORT = 50000 + SOURCE_PORT % num_mouse_flows
                # print ("Sending mouse_flow using Source_port : ",SOURCE_PORT)
                # total_packets_sent_mouse += client.send_data(mouse_flow_time,no_of_bytes_to_send,SOURCE_PORT)
                total_packets_sent_thread2 += client.send_data(
                    mouse_flow_time, no_of_bytes_to_send, SOURCE_PORT,
                    UDP_SERVER)
                if end_t2 == 59:
                    break
            print("total_packets_sent_thread2(short_flows) = ",
                  total_packets_sent_thread2)
            print("total time in thread2 = ",
                  (datetime.now() - time_thread2).total_seconds())

        if threadID == 2:
            # num_elephant_flows = 60
            time.sleep(5)
            time_thread1 = datetime.now()
            no_of_bytes_to_send = 1370
            elephant_flow_time = 10
            num_elephant_flows = int(total_exp_time / elephant_flow_time)
            total_packets_sent_elephant = 0
            for SOURCE_PORT in range(7005, 7050):
                print(
                    "Sending elephant_flow using Source_port in thread 3 = : ",
                    SOURCE_PORT)
                # total_packets_sent_elephant += client.send_data(elecphant_flow_time,no_of_bytes_to_send,SOURCE_PORT)
                total_packets_sent_thread3 += client.send_data(
                    elephant_flow_time, no_of_bytes_to_send, SOURCE_PORT,
                    UDP_SERVER)
                if end_t2 == 59:
                    break
            print("total_packets_sent_thread3 = ", total_packets_sent_thread3)
            print("total time in thread3 = ",
                  (datetime.now() - time_thread1).total_seconds())

        if threadID == 3:
            # num_elephant_flows = 60
            time.sleep(10)
            time_thread1 = datetime.now()
            no_of_bytes_to_send = 1370
            elephant_flow_time = 10
            num_elephant_flows = int(total_exp_time / elephant_flow_time)
            total_packets_sent_elephant = 0
            for SOURCE_PORT in range(7000, 7045):
                print(
                    "Sending elephant_flow using Source_port in thread 4 = : ",
                    SOURCE_PORT)
                # total_packets_sent_elephant += client.send_data(elecphant_flow_time,no_of_bytes_to_send,SOURCE_PORT)
                total_packets_sent_thread4 += client.send_data(
                    elephant_flow_time, no_of_bytes_to_send, SOURCE_PORT,
                    UDP_SERVER)
                if end_t2 == 59:
                    break
            print("total_packets_sent_thread4 = ", total_packets_sent_thread4)
            print("total time in thread4 = ",
                  (datetime.now() - time_thread1).total_seconds())
        if threadID == 4:
            # num_elephant_flows = 60
            time.sleep(10)
            time_thread1 = datetime.now()
            no_of_bytes_to_send = 1370
            elephant_flow_time = 10
            num_elephant_flows = int(total_exp_time / elephant_flow_time)
            total_packets_sent_elephant = 0
            for SOURCE_PORT in range(7005, 7050):
                print(
                    "Sending elephant_flow using Source_port in thread 4 = : ",
                    SOURCE_PORT)
                # total_packets_sent_elephant += client.send_data(elecphant_flow_time,no_of_bytes_to_send,SOURCE_PORT)
                total_packets_sent_thread4 += client.send_data(
                    elephant_flow_time, no_of_bytes_to_send, SOURCE_PORT,
                    UDP_SERVER)
                if end_t2 == 59:
                    break
            print("total_packets_sent_thread5 = ", total_packets_sent_thread4)
            print("total time in thread5 = ",
                  (datetime.now() - time_thread1).total_seconds())
        if threadID == 5:
            # num_elephant_flows = 60
            time.sleep(20)
            time_thread1 = datetime.now()
            no_of_bytes_to_send = 1370
            elephant_flow_time = 10
            num_elephant_flows = int(total_exp_time / elephant_flow_time)
            total_packets_sent_elephant = 0
            for SOURCE_PORT in range(7000, 7045):
                print(
                    "Sending elephant_flow using Source_port in thread 4 = : ",
                    SOURCE_PORT)
                # total_packets_sent_elephant += client.send_data(elecphant_flow_time,no_of_bytes_to_send,SOURCE_PORT)
                total_packets_sent_thread4 += client.send_data(
                    elephant_flow_time, no_of_bytes_to_send, SOURCE_PORT,
                    UDP_SERVER)
                if end_t2 == 59:
                    break
            print("total_packets_sent_thread6 = ", total_packets_sent_thread4)
            print("total time in thread6 = ",
                  (datetime.now() - time_thread1).total_seconds())
        if threadID == 6:
            # num_elephant_flows = 60
            time.sleep(15)
            time_thread1 = datetime.now()
            no_of_bytes_to_send = 1370
            elephant_flow_time = 10
            num_elephant_flows = int(total_exp_time / elephant_flow_time)
            total_packets_sent_elephant = 0
            for SOURCE_PORT in range(7005, 7045):
                print(
                    "Sending elephant_flow using Source_port in thread 4 = : ",
                    SOURCE_PORT)
                # total_packets_sent_elephant += client.send_data(elecphant_flow_time,no_of_bytes_to_send,SOURCE_PORT)
                total_packets_sent_thread4 += client.send_data(
                    elephant_flow_time, no_of_bytes_to_send, SOURCE_PORT,
                    UDP_SERVER)
                if end_t2 == 59:
                    break
            print("total_packets_sent_thread7 = ", total_packets_sent_thread4)
            print("total time in thread7 = ",
                  (datetime.now() - time_thread1).total_seconds())
        if threadID == 7:
            # num_elephant_flows = 60
            time.sleep(15)
            time_thread1 = datetime.now()
            no_of_bytes_to_send = 1370
            elephant_flow_time = 10
            num_elephant_flows = int(total_exp_time / elephant_flow_time)
            total_packets_sent_elephant = 0
            for SOURCE_PORT in range(7000, 7045):
                print(
                    "Sending elephant_flow using Source_port in thread 4 = : ",
                    SOURCE_PORT)
                # total_packets_sent_elephant += client.send_data(elecphant_flow_time,no_of_bytes_to_send,SOURCE_PORT)
                total_packets_sent_thread4 += client.send_data(
                    elephant_flow_time, no_of_bytes_to_send, SOURCE_PORT,
                    UDP_SERVER)
                if end_t2 == 59:
                    break
            print("total_packets_sent_thread8 = ", total_packets_sent_thread4)
            print("total time in thread8 = ",
                  (datetime.now() - time_thread1).total_seconds())
        if threadID == 8:
            # num_elephant_flows = 60
            time.sleep(15)
            time_thread1 = datetime.now()
            no_of_bytes_to_send = 1370
            elephant_flow_time = 10
            num_elephant_flows = int(total_exp_time / elephant_flow_time)
            total_packets_sent_elephant = 0
            for SOURCE_PORT in range(7000, 7045):
                print(
                    "Sending elephant_flow using Source_port in thread 4 = : ",
                    SOURCE_PORT)
                # total_packets_sent_elephant += client.send_data(elecphant_flow_time,no_of_bytes_to_send,SOURCE_PORT)
                total_packets_sent_thread4 += client.send_data(
                    elephant_flow_time, no_of_bytes_to_send, SOURCE_PORT,
                    UDP_SERVER)
                if end_t2 == 59:
                    break
            print("total_packets_sent_thread9 = ", total_packets_sent_thread4)
            print("total time in thread9 = ",
                  (datetime.now() - time_thread1).total_seconds())
def t_send(d):
    start = time.time()
    #print send_data(d).strip('\r\n')
    send_data(d)
    print 'send {0}, took {1}'.format(d, time.time() - start)
Exemple #13
0
def send_data():
    main_path = os.path.dirname(sys.path[0].strip())
    cron_status = main_path + "/tmp/monitor_cron.status"
    cron_data = main_path + "/tmp/monitor_info.dat"

    with open(cron_data) as f:
        data = f.read()
    with open(cron_status, 'r') as s_f:
        status = s_f.read()
    if len(status) == 0:
        try:
            f = open(cron_status, 'w')
            f.write('0')
            f.close()
        except Exception, e:
            log.log(e)
        sys.exit(1)
    if int(status.strip()) is not 0 or not data.__len__():
        log.log('Not collect data')
        return 0

    if client.send_data(data) is 0:
        try:
            f = open(cron_data, 'w')
            f.write('')
            f.close()
        except Exception, e:
            log.log(e)
            sys.exit(1)
Exemple #14
0
    if c is not None and DEBUG:
        # convert the (x, y) coordinates and radius of the circles to integers
        circles = np.round(c[0, :]).astype("int")

        # loop over the (x, y) coordinates and radius of the circles
        for (x, y, r) in circles:
            # draw the circle in the output image, then draw a rectangle
            # corresponding to the center of the circle
            cv2.circle(output, (x, y), r, (0, 255, 0), 4)
            cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5),
                          (0, 128, 255), -1)
            pass

        x, y, r = circles[0]
        #client.send_data(s, bytearray([ID_BYTE, 0, 0, x//256, x%256, 0, 0, y//256, y%256]))
        client.send_data(s, ','.join(map(str, [ID_BYTE, x, y, ""])))

    #bmask = cv2.inRange(hsv, blue_lower, blue_upper)
    # c = cv2.HoughCircles(img[:,:,2], cv2.HOUGH_GRADIENT, 0.5, 41, param1=30, param2=15, minRadius=5,maxRadius=15)
    # print(c)
    # if c is not None and DEBUG:
    #     # convert the (x, y) coordinates and radius of the circles to integers
    #     circles = np.round(c[0, :]).astype("int")

    #     max_x = 0
    #     # loop over the (x, y) coordinates and radius of the circles
    #     for (x, y, r) in circles:
    #         print(img[x, y,:])
    #         # draw the circle in the output image, then draw a rectangle
    #         # corresponding to the center of the circle
    #         cv2.circle(output, (x, y), r, (0, 255, 0), 4)