##// END OF EJS Templates
imanay -
r104:105
parent child
Show More
@@ -1,69 +1,69
1 import socket No newline at end of file
1 import socket
2 import string No newline at end of file
2 import string
3 No newline at end of file
3
4 def int2bin(n): No newline at end of file
4 def int2bin(n):
5 n_hex = "%x" %n No newline at end of file
5 n_hex = "%x" %n
6 ln = len(n_hex) No newline at end of file
6 ln = len(n_hex)
7 if ln == 1: No newline at end of file
7 if ln == 1:
8 n_hex = "00000" + n_hex No newline at end of file
8 n_hex = "00000" + n_hex
9 elif ln == 2: No newline at end of file
9 elif ln == 2:
10 n_hex = "0000" + n_hex No newline at end of file
10 n_hex = "0000" + n_hex
11 elif ln == 3: No newline at end of file
11 elif ln == 3:
12 n_hex = "000" + n_hex No newline at end of file
12 n_hex = "000" + n_hex
13 elif ln == 4: No newline at end of file
13 elif ln == 4:
14 n_hex = "00" + n_hex No newline at end of file
14 n_hex = "00" + n_hex
15 elif ln == 5: No newline at end of file
15 elif ln == 5:
16 n_hex = "0" + n_hex No newline at end of file
16 n_hex = "0" + n_hex
17 No newline at end of file
17
18 byte1 = n_hex[0:2] No newline at end of file
18 byte1 = n_hex[0:2]
19 byte2 = n_hex[2:4] No newline at end of file
19 byte2 = n_hex[2:4]
20 byte3 = n_hex[4:6] No newline at end of file
20 byte3 = n_hex[4:6]
21 str_len = "" No newline at end of file
21 str_len = ""
22 str_len += "%c" % string.atoi(byte1,16) No newline at end of file
22 str_len += "%c" % string.atoi(byte1,16)
23 str_len += "%c" % string.atoi(byte2,16) No newline at end of file
23 str_len += "%c" % string.atoi(byte2,16)
24 str_len += "%c" % string.atoi(byte3,16) No newline at end of file
24 str_len += "%c" % string.atoi(byte3,16)
25 No newline at end of file
25
26 return str_len No newline at end of file
26 return str_len
27 No newline at end of file
27
28 def int2str(n): No newline at end of file
28 def int2str(n):
29 str_n = str(n) No newline at end of file
29 str_n = str(n)
30 l_n = len(str_n) No newline at end of file
30 l_n = len(str_n)
31 if l_n == 1: No newline at end of file
31 if l_n == 1:
32 str_n = "00000" + str_n No newline at end of file
32 str_n = "00000" + str_n
33 elif l_n == 2: No newline at end of file
33 elif l_n == 2:
34 str_n = "0000" + str_n No newline at end of file
34 str_n = "0000" + str_n
35 elif l_n == 3: No newline at end of file
35 elif l_n == 3:
36 str_n = "000" + str_n No newline at end of file
36 str_n = "000" + str_n
37 elif l_n == 4: No newline at end of file
37 elif l_n == 4:
38 str_n = "00" + str_n No newline at end of file
38 str_n = "00" + str_n
39 elif l_n == 5: No newline at end of file
39 elif l_n == 5:
40 str_n = "0" + str_n No newline at end of file
40 str_n = "0" + str_n
41 return str_n No newline at end of file
41 return str_n
42 No newline at end of file
42
43 i=1 No newline at end of file
43 i=1
44 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)
45 host = "192.168.1." + str(i) No newline at end of file
45 host = "192.168.1." + str(i)
46 s.connect((host, 5500)) No newline at end of file
46 s.connect((host, 5500))
47
47
No newline at end of file
48 fd = open("input3.txt","r") No newline at end of file
48 fd = open("input2.txt","r") No newline at end of file
49 FileList = fd.readlines() No newline at end of file
49 FileList = fd.readlines()
50 data = "".join(FileList) No newline at end of file
50 data = "".join(FileList)
51
51
No newline at end of file
52 cmd = "SNDF" No newline at end of file
52 cmd = "ANST" No newline at end of file
53 No newline at end of file
53
54 dfl = 0 No newline at end of file
54 dfl = 0
55 lng = int2str(dfl) No newline at end of file
55 lng = int2str(dfl)
56 msg = "jro" + "abs" + "clnt_01" + "clnt_02" + lng + cmd + data + "0" # No newline at end of file
56 msg = "jro" + "abs" + "clnt_01" + "clnt_02" + lng + cmd + data + "0" #
57 lmsg = len(msg) No newline at end of file
57 lmsg = len(msg)
58 lng = int2str(lmsg) No newline at end of file
58 lng = int2str(lmsg)
59 No newline at end of file
59
60 msg = "jro" + "abs" + "clnt_01" + "clnt_02" + lng + cmd + data + "0" # No newline at end of file
60 msg = "jro" + "abs" + "clnt_01" + "clnt_02" + lng + cmd + data + "0" #
61 s.send(msg) No newline at end of file
61 s.send(msg)
62 print "Enviado " + str(len(msg)) + " bytes." No newline at end of file
62 print "Enviado " + str(len(msg)) + " bytes."
63 No newline at end of file
63
64 recibido = s.recv(512) No newline at end of file
64 recibido = s.recv(512)
65 No newline at end of file
65
66 print "Recibido: " + recibido No newline at end of file
66 print "Recibido: " + recibido
67 No newline at end of file
67
68 s.close() No newline at end of file
68 s.close()
69 No newline at end of file
69
General Comments 0
You need to be logged in to leave comments. Login now