Example of my current server side code (This will stay in the terminal)
import socket
import threading
port = 7064
server = "0.0.0.0"
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((server, port))
server_socket.listen(5)
def client_thread_code(addr, client_sock):
client_sock.send("Ping".encode("utf8"))
try:
while True:
# Accepts and sorts user connections to server.
(client_sock, addr) = server_socket.accept()
print("Connection from: " + str(addr))
# Spawns client thread
# socket is blocking so offload to thread.
client_thread = threading.Thread(target=client_thread_code, args=(addr, client_sock,)).start()
except Exception as exception:
print("Critical Error Server halted " + str(exception))
The client would be a complicated version of this:
import socket
server = "localhost"
port = 7064
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((server, port))
print(client_socket.recv(1024).decode("utf8"))
Is there any way to move the client functionality to a website so a client could access it through a browser.