##// END OF EJS Templates
Testing frame without semicolon.
imanay -
r102:103
parent child
Show More
@@ -1,92 +1,69
1 import socket No newline at end of file
1 import socket
2 import string
2 import string
No newline at end of file
3 #import time No newline at end of file
4 No newline at end of file
3
5 def int2bin(n): No newline at end of file
4 def int2bin(n):
6 n_hex = "%x" %n No newline at end of file
5 n_hex = "%x" %n
7 ln = len(n_hex) No newline at end of file
6 ln = len(n_hex)
8 if ln == 1: No newline at end of file
7 if ln == 1:
9 n_hex = "00000" + n_hex No newline at end of file
8 n_hex = "00000" + n_hex
10 elif ln == 2: No newline at end of file
9 elif ln == 2:
11 n_hex = "0000" + n_hex No newline at end of file
10 n_hex = "0000" + n_hex
12 elif ln == 3: No newline at end of file
11 elif ln == 3:
13 n_hex = "000" + n_hex No newline at end of file
12 n_hex = "000" + n_hex
14 elif ln == 4: No newline at end of file
13 elif ln == 4:
15 n_hex = "00" + n_hex No newline at end of file
14 n_hex = "00" + n_hex
16 elif ln == 5: No newline at end of file
15 elif ln == 5:
17 n_hex = "0" + n_hex No newline at end of file
16 n_hex = "0" + n_hex
18 No newline at end of file
17
19 byte1 = n_hex[0:2] No newline at end of file
18 byte1 = n_hex[0:2]
20 byte2 = n_hex[2:4] No newline at end of file
19 byte2 = n_hex[2:4]
21 byte3 = n_hex[4:6] No newline at end of file
20 byte3 = n_hex[4:6]
22 str_len = "" No newline at end of file
21 str_len = ""
23 str_len += "%c" % string.atoi(byte1,16) No newline at end of file
22 str_len += "%c" % string.atoi(byte1,16)
24 str_len += "%c" % string.atoi(byte2,16) No newline at end of file
23 str_len += "%c" % string.atoi(byte2,16)
25 str_len += "%c" % string.atoi(byte3,16) No newline at end of file
24 str_len += "%c" % string.atoi(byte3,16)
26 No newline at end of file
25
27 return str_len No newline at end of file
26 return str_len
28 No newline at end of file
27
29 def int2str(n): No newline at end of file
28 def int2str(n):
30 str_n = str(n) No newline at end of file
29 str_n = str(n)
31 l_n = len(str_n) No newline at end of file
30 l_n = len(str_n)
32 if l_n == 1: No newline at end of file
31 if l_n == 1:
33 str_n = "00000" + str_n No newline at end of file
32 str_n = "00000" + str_n
34 elif l_n == 2: No newline at end of file
33 elif l_n == 2:
35 str_n = "0000" + str_n No newline at end of file
34 str_n = "0000" + str_n
36 elif l_n == 3: No newline at end of file
35 elif l_n == 3:
37 str_n = "000" + str_n No newline at end of file
36 str_n = "000" + str_n
38 elif l_n == 4: No newline at end of file
37 elif l_n == 4:
39 str_n = "00" + str_n No newline at end of file
38 str_n = "00" + str_n
40 elif l_n == 5: No newline at end of file
39 elif l_n == 5:
41 str_n = "0" + str_n No newline at end of file
40 str_n = "0" + str_n
42 return str_n No newline at end of file
41 return str_n
43
42
No newline at end of file
43 i=1 No newline at end of file
44
No newline at end of file
45 #ini = time.time()
No newline at end of file
46 #sum = 0
No newline at end of file
47
No newline at end of file
48 #for i in range(11,15):
No newline at end of file
49 i=117
No newline at end of file
50 #ini1 = time.time() No newline at end of file
51 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) No newline at end of file
44 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
52 host = "192.168.1." + str(i) No newline at end of file
45 host = "192.168.1." + str(i)
53 s.connect((host, 5500)) No newline at end of file
46 s.connect((host, 5500))
54
47
No newline at end of file
48 fd = open("input2.txt","r") No newline at end of file
55 fd = open("experimento2.abs","r") No newline at end of file
56 FileList = fd.readlines() No newline at end of file
49 FileList = fd.readlines()
57 data = "".join(FileList) No newline at end of file
50 data = "".join(FileList)
58 No newline at end of file
51
52 cmd = "ANST"
No newline at end of file
53 No newline at end of file
59 dfl = 0
54 dfl = 0
No newline at end of file
60 #lng = int2bin(dfl) No newline at end of file
61 lng = int2str(dfl)
55 lng = int2str(dfl)
No newline at end of file
56 msg = "jro" + "abs" + "clnt_01" + "clnt_02" + lng + cmd + data + "0" # No newline at end of file
62 msg = "jro" + "abs" + "src" + "cm1" + lng + "cmd" + data + "crc" #
No newline at end of file
63 print len(msg)
No newline at end of file
64 print msg
No newline at end of file
65 No newline at end of file
66 lmsg = len(msg)
57 lmsg = len(msg)
No newline at end of file
67 #lng = int2bin(lmsg) No newline at end of file
68 lng = int2str(lmsg) No newline at end of file
58 lng = int2str(lmsg)
69
59
No newline at end of file
60 msg = "jro" + "abs" + "clnt_01" + "clnt_02" + lng + cmd + data + "0" #
70 msg = "jro" + "abs" + "src" + "cm1" + lng + "cmd" + data + "crc" #
No newline at end of file
No newline at end of file
61 s.send(msg)
71 print len(msg)
No newline at end of file
No newline at end of file
62 print "Enviado " + str(len(msg)) + " bytes." No newline at end of file
72 #print msg No newline at end of file
73 No newline at end of file
63
64 recibido = s.recv(512) No newline at end of file
74
65
No newline at end of file
66 print "Recibido: " + recibido No newline at end of file
75 s.send(msg)
No newline at end of file
76 #recibido = s.recv(512)
No newline at end of file
77
No newline at end of file
78 #print recibido No newline at end of file
79 No newline at end of file
67
80 s.close() No newline at end of file
68 s.close()
81
69
No newline at end of file
82
No newline at end of file
83 # delay = time.time() - ini1
No newline at end of file
84 # sum += delay
No newline at end of file
85 # print delay
No newline at end of file
86 # time.sleep(0.1)
No newline at end of file
87
No newline at end of file
88 #print sum
No newline at end of file
89
No newline at end of file
90
No newline at end of file
91
No newline at end of file
92 No newline at end of file
@@ -1,40 +1,62
1 import socket No newline at end of file
1 import socket
2 import time No newline at end of file
2 import time
3
No newline at end of file
4 def int2str(n):
No newline at end of file
5 str_n = str(n)
No newline at end of file
6 l_n = len(str_n)
No newline at end of file
7 if l_n == 1:
No newline at end of file
8 str_n = "00000" + str_n
No newline at end of file
9 elif l_n == 2:
No newline at end of file
10 str_n = "0000" + str_n
No newline at end of file
11 elif l_n == 3:
No newline at end of file
12 str_n = "000" + str_n
No newline at end of file
13 elif l_n == 4:
No newline at end of file
14 str_n = "00" + str_n
No newline at end of file
15 elif l_n == 5:
No newline at end of file
16 str_n = "0" + str_n
No newline at end of file
17 return str_n No newline at end of file
3 No newline at end of file
18
4 host = "192.168.1.117" No newline at end of file
19 host = "192.168.1.117"
5 s = socket.socket() No newline at end of file
20 s = socket.socket()
6 s.bind((host, 5500)) No newline at end of file
21 s.bind((host, 5500))
7 No newline at end of file
22
8 while True: No newline at end of file
23 while True:
9 print "waiting client..." No newline at end of file
24 print "waiting client..."
10 s.listen(1) No newline at end of file
25 s.listen(1)
11 No newline at end of file
26
12 sc, addr = s.accept() No newline at end of file
27 sc, addr = s.accept()
13 No newline at end of file
28
14 all = "" No newline at end of file
29 all = ""
15 No newline at end of file
30
16 # i=0 #to avoid infinit loop No newline at end of file
31 # i=0 #to avoid infinit loop
17 cnt = 0; No newline at end of file
32 cnt = 0;
18 first = 0; No newline at end of file
33 first = 0;
19 while True: No newline at end of file
34 while True:
20 recibido = sc.recv(1024) No newline at end of file
35 recibido = sc.recv(1024)
21 all = all + recibido No newline at end of file
36 all = all + recibido
22 cnt = len(all) No newline at end of file
37 cnt = len(all)
23 if first == 0: No newline at end of file
38 if first == 0:
24 first = 1;
39 first = 1;
No newline at end of file
40 lng = int(all[21:27]) # 6 bytes to get the frame size No newline at end of file
25 lng = int(all[12:18]) # 6 bytes to get the frame size No newline at end of file
26 No newline at end of file
41
27 # i = i + 1 No newline at end of file
42 # i = i + 1
28 # if cnt == lng or i == 30: No newline at end of file
43 # if cnt == lng or i == 30:
29 if cnt == lng: No newline at end of file
44 if cnt == lng:
30 break No newline at end of file
45 break
31 No newline at end of file
46
32 No newline at end of file
47 print "\nSize of frame:" + str(lng)
33 No newline at end of file
48 print "\nNumber of bytes received:" + str(cnt)
34 print "\nSize of frame:" + str(lng) No newline at end of file
49
35 print "\nNumber of bytes received:" + str(cnt) No newline at end of file
50 data = "ok"
36 No newline at end of file
51 dfl = 0
52 lng = int2str(dfl)
No newline at end of file
53 msg = "jro" + "abs" + "src" + "cm1" + lng + "cmd" + data + "crc" #
No newline at end of file
54 lmsg = len(msg)
No newline at end of file
55 lng = int2str(lmsg)
No newline at end of file
56
No newline at end of file
57 msg = "jro" + "abs" + "src" + "cm1" + lng + "cmd" + data + "crc" #
No newline at end of file
58 sc.send(msg)
No newline at end of file
59 print "Enviando respuesta en " + str(len(msg)) + " bytes."
No newline at end of file
60
No newline at end of file
61 sc.close()
No newline at end of file
62 s.close() No newline at end of file
37 sc.close() No newline at end of file
63 L63: rhodecode diff rendering error
38 s.close()
64 L64: rhodecode diff rendering error
No newline at end of file
39
No newline at end of file
40 #print len(recibido) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now