I a server and client for a socket connection in Python,
client:
import socket
import sys
from sys import stdin
serv = 'ip goes here'
port = 8888
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((serv, port))
def prompt():
sys.stdout.write('<You> ')
sys.stdout.flush()
def send(x):
sock.sendall(x)
rec = 0
ex = len(x)
while rec < ex:
data = sock.recv(16)
rec += len(data)
while 1:
if sock:
data = sock.recv(16)
if len(data) == 0:
pass
print '<Server> %s' % data
prompt()
msg = stdin.readline()
sock.sendall(msg)
The way I have it now, if you say something on one client, it will send "alphabet" to both clients but the other clients will not receive that until they send a new message as it is waiting for stdin.readline() to occur. I was wondering how to make it so the clients will always receive data from the server, and will see it without having to have stdin.readline() happen first.
Thanks