0

I'm developing an app and I want to send msgs from the client socket (TCP) to the server socket. I want to send 3 messages, send one, wait till the ACK from the server, send another msg wait till the ACK from the server... This is my code (client side):

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
    sock.connect((host,port))
    sock.sendall(bytes(INIT_MSG, "UTF-8"))
    sock.sendall(bytes(FREQ_MSG, "UTF-8"))
    sock.sendall(bytes(KEY_MSG, "UTF-8"))

And in server side:

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.bind(("",PORT))
    s.listen()
    counter = 0
    conn, addr = s.accept()
    print("Connected by:", addr)
    while True:
        data = conn.recv(1024)
        if not data:
            break

But when I use Wireshark to look at the frames, all the data is send in one frame instead of 3. I believe the main problem is in the server side which accepts 1024b. How can I fix it?

  • I see you've posted some code, but I see no attempt at making the server send an ACK, nor the client waiting for it. – quamrana Aug 07 '22 at 12:57
  • As far as I read, recv() send automatically the ACK and I can see it through Wireshark. So, I'm trying to figure out how to wait until ACK is received in client side – Guillermo Fuentes Morales Aug 07 '22 at 13:03
  • 1
    Oh, that ACK is invisible to clients. – quamrana Aug 07 '22 at 13:05
  • The unique solution I've thought is to send back a msg from the server side, something like "Ok" and make the client wait till this msg is received with a sock.recv() but I'm sure this is not the best implementation. So I'd like to know if there is someway to wait until the ACK. – Guillermo Fuentes Morales Aug 07 '22 at 13:14
  • There is no ACK with stream sockets that is detectable through the sockets API. If you're talking about TCP ACKs you never see those, they're handled at a very low level in the operating system TCP stack. [This answer](https://stackoverflow.com/a/43420503/238704) about stream sockets is worth reading. – President James K. Polk Aug 07 '22 at 13:24

0 Answers0