##// END OF EJS Templates

File last commit:

r85:86
r85:86
Show More
client.py
74 lines | 1.3 KiB | text/x-python | PythonLexer
import socket
import string
#import time
def int2bin(n):
n_hex = "%x" %n
ln = len(n_hex)
if ln == 1:
n_hex = "00000" + n_hex
elif ln == 2:
n_hex = "0000" + n_hex
elif ln == 3:
n_hex = "000" + n_hex
elif ln == 4:
n_hex = "00" + n_hex
elif ln == 5:
n_hex = "0" + n_hex
byte1 = n_hex[0:2]
byte2 = n_hex[2:4]
byte3 = n_hex[4:6]
str_len = ""
str_len += "%c" % string.atoi(byte1,16)
str_len += "%c" % string.atoi(byte2,16)
str_len += "%c" % string.atoi(byte3,16)
return str_len
#ini = time.time()
#sum = 0
#for i in range(11,15):
i=117
#ini1 = time.time()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = "192.168.1." + str(i)
s.connect((host, 5500))
fd = open("experimento1.abs","r")
FileList = fd.readlines()
data = "".join(FileList)
dfl = 0
lng = int2bin(dfl)
msg = "jro" + "abs" + "src" + "cm1" + lng + "cmd" + data + "crc" #
print len(msg)
print msg
lmsg = len(msg)
lng = int2bin(lmsg)
msg = "jro" + "abs" + "src" + "cm1" + lng + "cmd" + data + "crc" #
print len(msg)
print msg
total_len = len(msg) + 3
s.send(mensaje)
#recibido = s.recv(512)
print recibido
s.close()
# delay = time.time() - ini1
# sum += delay
# print delay
# time.sleep(0.1)
#print sum