Multiple commands in one connection - unpredictable


I'm having a problem with running application that interacts with Zebra 110PAX4 printer.

The case is that I'm trying to put print date on printed label. The printer is put on production line, where printing next label is halted until the line is ready to accept next label.

I'm using ~HS to check whether previous label has been printed. If ~HS returns that there is still at least one label in printer I'm sending ~JA and resending previous page with updated time. This happens in one TCP/IP connection.

Unfortunately the after sending ~HS followed by ~JA with next label the printer sometimes does not accept connections (Connection refused is returned from TCP stack) or the previous label does not get cleared and two labels are printer.

Is my approach correct to use ~HS combined with ~JA and sending next label?
Should I send each command in separate TCP connection?

How come that after sending ~JA printer responds to ~HS with zero pages in buffer but labels still get printed?

I'm completly lost. Could you please help me?