1

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.

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
Illin Tori
  • 11
  • 1
  • You can do it totally. But it depends on what you mean as a website, is it a static HTML one or website powered by some python backing such as Flask/Django? – St1id3r Jun 03 '18 at 20:02
  • 4
    Possible duplicate of [Connecting to TCP Socket from browser using javascript](https://stackoverflow.com/questions/12407778/connecting-to-tcp-socket-from-browser-using-javascript), [How to access TCP Socket via web client](https://stackoverflow.com/questions/27571414), [How do I use a browser as a client in python sockets?](https://stackoverflow.com/questions/25741177) and [probably more](https://www.google.com/search?q=site%3Astackoverflow.com+access+sockets+from+browser) – Steffen Ullrich Jun 03 '18 at 20:42
  • @St1id3r Ideally it would be done with Flask/Django but I have only found web sockets for them. – Illin Tori Jun 04 '18 at 05:38

0 Answers0