-
Notifications
You must be signed in to change notification settings - Fork 0
/
ldpc-client.py
43 lines (37 loc) · 1.28 KB
/
ldpc-client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Ldpc client program
# Este programa se encarga de recibir comandos del servidor que consisten en ejecutar las tareas dictadas por el mismo y devolver la salida
import socket,os,struct
#-------- configuracion ---------------
HOST = 'alerce.itba.edu.ar' # The remote host
PORT = 50008 # The same port as used by the server
#--------------------------------------
print "Connecting to %s:%d" % (HOST,PORT)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
while(True):
data = s.recv(1)
if len(data)==0: # no more data?
exit(0)
print 'Received command %s' % (data)
if (data=='Q'): # Q= comando de salir
exit(0)
if (data=='E'): # E= comando de eco
s.send('E')
if (data=='C'): # C= comando de empezar tarea
clientsnumber = ord(s.recv(1))
command = './pipes-clientserver.sh %d > salidaclient%d.txt' % (clientsnumber,clientsnumber)
print "Executing command '%s'" % command
os.system(command)
if (data=='R'): # R= comando de devolver datos
clientsnumber = ord(s.recv(1))
outfile= 'salidaclient%d.txt' % clientsnumber
print "Sending file '%s' to server" % outfile
try:
fil=open(outfile,'rb')
data=fil.read()
fil.close()
os.unlink(outfile)
except: data=''
s.send(struct.pack("<L",len(data)))
s.sendall(data)
s.close()