##// END OF EJS Templates
testing threading
testing threading

File last commit:

r102:103
r163:164
Show More
server.py
61 lines | 1.4 KiB | text/x-python | PythonLexer
r59 import socket
import time
r53
Testing frame without semicolon.
r102 def int2str(n):
str_n = str(n)
l_n = len(str_n)
if l_n == 1:
str_n = "00000" + str_n
elif l_n == 2:
str_n = "0000" + str_n
elif l_n == 3:
str_n = "000" + str_n
elif l_n == 4:
str_n = "00" + str_n
elif l_n == 5:
str_n = "0" + str_n
return str_n
r85 host = "192.168.1.117"
r52 s = socket.socket()
r53 s.bind((host, 5500))
r69
while True:
print "waiting client..."
s.listen(1)
r52
r69 sc, addr = s.accept()
Modificaciones en servidor tcp para evitar perdida de datos en funcion recv
r65
r69 all = ""
Testing frame transfer without colon.
r91
# i=0 #to avoid infinit loop
r85 cnt = 0;
Testing frame transfer without colon.
r91 first = 0;
r69 while True:
recibido = sc.recv(1024)
Testing frame transfer without colon.
r91 all = all + recibido
cnt = len(all)
if first == 0:
first = 1;
Testing frame without semicolon.
r102 lng = int(all[21:27]) # 6 bytes to get the frame size
Testing frame transfer without colon.
r91
# i = i + 1
# if cnt == lng or i == 30:
if cnt == lng:
r69 break
Testing frame without semicolon.
r102
Testing frame transfer without colon.
r91 print "\nSize of frame:" + str(lng)
print "\nNumber of bytes received:" + str(cnt)
Testing frame without semicolon.
r102
data = "ok"
dfl = 0
lng = int2str(dfl)
msg = "jro" + "abs" + "src" + "cm1" + lng + "cmd" + data + "crc" #
lmsg = len(msg)
lng = int2str(lmsg)
msg = "jro" + "abs" + "src" + "cm1" + lng + "cmd" + data + "crc" #
sc.send(msg)
print "Enviando respuesta en " + str(len(msg)) + " bytes."
Modificaciones en servidor tcp para evitar perdida de datos en funcion recv
r65
r52 sc.close()
Testing frame without semicolon.
r102 s.close()