Filip craqow
Filip craqow

Reputation: 21

Is there a way to run two servers at the same time independently?

I want to make flask app that displays data that the socket server recieves from other client is

Is there a way to run this code:

import socket

def server():
    host = socket.gethostname()
    port = 8080 

    server_socket = socket.socket()  

    server_socket.bind((host, port)) 
    
    server_socket.listen(2)
    conn, address = server_socket.accept()  
    
    print("Connection from: " + str(address))

    while True:

        data = conn.recv(1024).decode()

        if str(data) == "Connection closed":
            break
        elif not data:
            break

        print("Data: " + str(data))
    
    conn.close() 

if __name__ == '__main__':
    server()

And this:

from flask import Flask

app = Flask(__name__)

@app.route("/data")
def data_from_server():
    return "Data that server recieved"

in the same python file, i tried doing it with threading but when i did it the first server started running and the second didn't however when i close first server the second starts working

Upvotes: 0

Views: 31

Answers (0)

Related Questions