Skip to content
  • 0 Votes
    7 Posts
    431 Views
    L

    well at the end i simply sended all the data and split everything inside a list, not the best thing to do but it works, heres the code

    def servidorMk3(): host = socket.gethostname() host_port = 8000 host_ip = socket.gethostbyname(host) buffer = 1024 code_end = "<END>" code_ok = "<OK>" code_fin = "<FIN>" code_sep = "<SEP>" nombre, size, dataFile, elemt = [], [], [], [] print (f"Servidor Mk3") print (f"Ip del servidor: " + host_ip) log("Inicio del servidorMk3 " + host_ip) with socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) as tcp_conn: tcp_conn.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) tcp_conn.bind((host_ip, host_port)) tcp_conn.listen(1) con, adrs = tcp_conn.accept() print (f"Conecion Exitosa") log("Connecion exitosa con el server: " + adrs[0]) while True: alldata = con.recv(buffer) while True: # recibe la info en general alldata = alldata + con.recv(buffer) if code_fin.encode("utf8") in alldata: # si llega <FIN>, se acabo la lista break data = alldata.split(b'<SEP>') #separar manualmente while code_fin.encode("utf8") in data: data.remove(code_fin.encode("utf8")) for i in range(0, len(data),3): bloque = data[i:i+3] nombre.append(bloque[0].decode("utf8")) print(nombre) size.append(bloque[1].decode("utf8")) dataFile.append(bloque[2]) directorio = crear_directorio() for x in range(len(nombre)): if directorio == "<BAD>": print(" no se puede crear la ubicacion") print(type(directorio)) # revisar el tipo que regresa esta funcion¡¡¡¡ print(directorio) break else: print(f"0 .. {nombre[x]}") print(f"1 .. {size[x]}") #print (dataFile) file_name = directorio + nombre[x] # path to the file, file_size = int(size[x]) # size of file file_create = open(file_name, 'wb') # open file for writing in binary file_create.write(dataFile[x]) # writes to the file file_create.close() #close the file check = os.path.getsize(file_name) # returns the size of the file print (f"Tamaño esperado: {file_size} ... tamaño real {check} ") if check == file_size: log("archivo " + file_name + " creado, tamaño: " + str(file_size)) else: log("No se pudo crear el archivo: " + file_name) if x == len(nombre): log("Respaldo de Archivos completado") tcp_conn.close() print(f"Respaldo de archivos terminada")
  • 0 Votes
    1 Posts
    657 Views
    No one has replied
  • 0 Votes
    6 Posts
    816 Views
    ODБOïO

    @thisisseven said in QTOpcUa -- connectToEndPoint Error:

    "opc.tcp://localhost:4840"

    76327cf3-2042-4ff5-9db4-a6900ceed2b5-image.png

    https://doc-snapshots.qt.io/qtopcua/qopcuaclient.html#connectToEndpoint
    https://doc-snapshots.qt.io/qtopcua/qopcuaclient.html#usage

  • 0 Votes
    7 Posts
    1k Views
    V

    @aha_1980
    ok, thanks help again.
    regards.

  • 0 Votes
    6 Posts
    3k Views
    VRoninV

    QTcpSocket socMeteo;
    QTextStream texte(&socHauteur);

    These are 2 different sockets. What are you trying to do?

    It should be something like:

    auto socMeteo = new QTcpSocket(this); socMeteo->connectToHost("192.168.1.35",10001); connect(socMeteo,&QTcpSocket::connected,socMeteo,[socMeteo]()->void{ QTextStream texte(socMeteo); texte<<"Bonsoir\n"; });
  • 0 Votes
    23 Posts
    16k Views
    PangolinP

    @puzzled_giraffe
    QTcpsocket have not got "connectState" setup? I think qt use long tcp connection by default.

  • 0 Votes
    1 Posts
    897 Views
    No one has replied
  • 0 Votes
    4 Posts
    6k Views
    VRoninV

    The handshake is the process that establishes the secure connection, in Qt QSslSocket::connectToHostEncrypted and QSslSocket::startServerEncryption take care of the handshake. The "Hello Word" sent across is just normal TCP communication that could be done even without encryption (i.e. using QTcpSocket)

  • 0 Votes
    17 Posts
    7k Views
    kshegunovK

    @marlenet15
    Hi,
    Here you can find a threaded TCP server example. You can ignore the module specific classes QDaemonApplication (think of it as QCoreApplication) and QDaemonLog you can substitute with QDebug.

    Enjoy!
    Kind regards.

  • Client-Server. Send data

    Unsolved General and Desktop
    2
    0 Votes
    2 Posts
    2k Views
    SGaistS

    Hi,

    You have the Fortune server and Fortune client that can serve as base to get you started. The main "detail" is that you want to exchange the sender and receiver part but the technique described there is still valid.

    Out of curiosity, how much is "large amount of data" ?

  • 0 Votes
    10 Posts
    6k Views
    SGaistS

    @stereomatchingkiss Indeed, such a huge amount of connections in such a short time would rather need a thread pool, otherwise you're going to starve your system.