Hello, all professionals
I aim to create three scripts (one in Host, the other two in 2 different Guests) realizing server vs multi-clients communications.
There is a file in my Host system, what I propose to do is transmitting lines in that file to different Guests.
Following is the raw code I wrote for Host:

import socket, fileinput
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((' ', 2000))
s.listen(2)
conn, addr = s.accept()
for data in fileinput.input("/path/data.txt"):
      conn.send(data)
conn.close()

Let's say, I created 6 lines in my data.txt with each line is only a number calculated from 1 to 6.
How to implement:

Transmitting first 3 digits to the first Guest and the other 3 digits to the second Guest?


Thank you for all your cordially helps.
I am grateful for your considerations.

send them three at once maybe? Now looks like you send whole file to each.

Your for loop should roughly be like this:

file = open('/path/data.txt', 'r')
for i in range(3):
  data = file.readline()#Each number is in one line, so you will send the first 3 numbers
  conn.send(data)
#Here you have to connect to second guest
for i in range(3): #next 3 digits to next guest
  data = file.readline()
  conn.send(data)

Your for loop should roughly be like this:

file = open('/path/data.txt', 'r')
for i in range(3):
  data = file.readline()#Each number is in one line, so you will send the first 3 numbers
  conn.send(data)
#Here you have to connect to second guest
for i in range(3): #next 3 digits to next guest
  data = file.readline()
  conn.send(data)

Thank you for the efficient answer..
I appreciate your great help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.