I'm trying to write a server-client(s) program in python using the socket and the threading module. I would like to send and receive to and from the client a confirmation data packet to check if it is still connected to the server and, simultaneously, I would like to be able to ask for input from the server user and then send it whenever the server user presses enter. I think a possible way to achieve that is just using two simultaneous threads, one that sends a validation data packet and the other that sands server user input. The syntax would look like the following:
import threading
import socket
def confirmation():
# do confirmation
def send_server_input():
# send the user server input
confirmation_thread = threading.Thread(target=confirmation)
confirmation_thread.start()
send_server_input_thread = threading.Thread(target=send_server_input)
send_server_input_thread.start
But I'm afraid that this way won't work, because the data packets may "get confused" or "collapse" one into the other. And if that doesn't happen, how can I distinguish one from the other from the client side this to data packets?
Thank you very much for your time and excuse my English, I'm still practising it!