BhavinT
BhavinT

Reputation: 332

Network Cluster Builder Python

I am developing a client server network using python. I want a network that has multiple clients connected to a single server and that server will acts as client and this client is connected to multiple servers. How can I do it. I have written some function for connection and sending data Here is the code:

import socket

def streamServerConnect(tcpIP,tcpPort):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((tcpIP, tcpPort))
    s.listen(1)
    conn, addr = s.accept()
    return conn, addr

def streamClientConnect(tcpIP,tcpPort):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((tcpIP, tcpPort))
    return s

def streamServerReceive(conn,bufferSize):
    while 1:
        data=conn.recv(bufferSize)
        if not data: break
        bufferQueue.append(data.decode())
        conn.send(data)
    conn.close()
    return bufferQueue

def streamClientSend(socket,bufferSize,message):
    socket.send(message.encode())
    data=socket.recv(bufferSize)
    socket.close()
    return data

I am not getting how should I design my server to accept connection and receive data simultaneously from multiple clients and make server as a client simultaneously and connect to multiple servers. Can Anyone please help me?. I want a network like thisflowGraph

Upvotes: 0

Views: 66

Answers (1)

Beny Gj
Beny Gj

Reputation: 615

you should'nt do this , what you wont to implement is load balancing

you should use ha proxy - client post request -> haproxy handle it ->
redirect to the server server -> send response via haproxy to the client.

Upvotes: 1

Related Questions