Reputation: 332
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 this
Upvotes: 0
Views: 66