def readSendVideo(Videopath: str, socket: Socket):
    messagevid = {}
    with open(Videopath, 'rb') as vfile:
        file = vfile.read()
        messagevid['VIDEO'] = file
    socket.send_pyobj(messagevid)
    return True
Ejemplo n.º 2
0
def downloadFile(fileName: str, masterSocket: Socket):
    myMessegeSend = {'REQ_TYPE': 'download'}
    myMessegeSend['FILE_NAME'] = fileName
    masterSocket.send_pyobj(myMessegeSend)
    print("i have send a message")
    listMachines = masterSocket.recv_pyobj()
    print(listMachines)

    context = zmq.Context()
    downloadSocketDk = context.socket(zmq.REQ)
    for IP, port in listMachines['DK_INFO']:
        print(IP, port)
        downloadSocketDk.connect("tcp://" + str(IP) + ":%s" % port)
        break
    Message = {"VIDEO_NAME": fileName}
    downloadSocketDk.send_pyobj(Message)
    video = downloadSocketDk.recv_pyobj()
    print(video)
    saveVideo(video, fileName)
Ejemplo n.º 3
0
def uploadFile(videoPath: str, socketClientMaster: Socket):
    '''
    steps :
    1-request upload 2-recieve information of the data keeper
    3-establish connection 4-send the video
    '''
    myMessegeSend = {'REQ_TYPE': 'upload'}
    socketClientMaster.send_pyobj(myMessegeSend)
    myMessegeRec = socketClientMaster.recv_pyobj()
    if (myMessegeRec['STATUS'] == 'fail'):
        print(
            'no ports are free at the current state please run again after a while'
        )
        exit()
    portNumberUpload = myMessegeRec['PORT_NUMBER']
    ip = myMessegeRec['IP']
    print(myMessegeRec)
    socketClientDataKeeper = establishUploadConnection(portNumberUpload, ip)
    readSendVideo(videoPath, socketClientDataKeeper)
Ejemplo n.º 4
0
def processor(
        src_socket: Socket,
        dst_socket: Socket,
        func:
    GDKC = identity,  # GDKC(cv2.cvtColor, kwargs=dict(code=cv2.COLOR_BGR2GRAY))
) -> None:
    """

    :param src_socket:
    :param dst_socket:
    :param func:
    """
    while True:
        dst_socket.send_pyobj(
            func(src_socket.recv_pyobj()),
            copy=False,
            track=False,
            # flags=zmq.NOBLOCK
        )
Ejemplo n.º 5
0
def zmq_export(sock: zmq.Socket, topic: str, data, datatype: str = "pyobj"):
    """
    Author:
    Alexander Heilmeier & Tim Stahl

    Description:
    Sends data via ZMQ.

    Inputs:
    sock:       ZMQ socket (see below how to create it)
    topic:      ZMQ topic to use
    data:       data to send
    datatype:   string that indicates if it should be sent as Python object (pyobj), json (json) or string (str)

    Hint: To send an object as string it must be converted to a string at first. Conversion of Python objects to json
    objects is handled by PyZMQ and therefore must not be done by hand if sending a json.

    How to create a ZMQ socket to export data?
    import zmq
    zmq_context = zmq.Context()
    sock = zmq_context.socket(zmq.PUB)
    sock.bind("tcp://*:%s" % port)
    """

    # ------------------------------------------------------------------------------------------------------------------
    # FUNCTION BODY ----------------------------------------------------------------------------------------------------
    # ------------------------------------------------------------------------------------------------------------------

    sock.send_string(topic, zmq.SNDMORE)

    if datatype == "pyobj":
        sock.send_pyobj(data)
    elif datatype == "json":
        sock.send_json(data)
    elif datatype == "str":
        sock.send_string(data)
    else:
        raise RuntimeError("Specified datatype is not supported!")
Ejemplo n.º 6
0
def send_pyobj(socket: zmq.Socket, data: Any, **kw) -> None:
    """
    Send python object.
    """
    socket.send_pyobj(data, **kw)