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.

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)

Edited 6 Years Ago by group256: n/a

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.

This article has been dead for over six months. Start a new discussion instead.