-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.py
41 lines (37 loc) · 1.24 KB
/
get.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
import socket
import sys
import time
import json
import random
TailleReseau = 20
def main(argv):
global TailleReseau
if (len(argv) == 3):
IP_Port=argv[0]
IP=IP_Port.split(':')[0]
PORT=IP_Port.split(':')[1]
node = argv[1]
key= argv[2]
print("Je cherche la clé :"+ str(key)+" en partant de "+str(IP)+":"+str(PORT))
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM);
time.sleep(.05)
print("j'envoi a "+str(IP)+":"+str(PORT))
s.connect((IP,int(PORT)))
messageAEnvoye = {"cmd": "get",
"args":{
"host" : {
"idNode" : int(node),
"IP" : IP,
"port" : int(PORT)
},
"key" : int(key),
}
}
jsonRes = json.dumps(messageAEnvoye)
jsonRes=bytes(jsonRes,'utf-8')
print("J'envoie "+str(jsonRes))
s.sendto(jsonRes,(IP, int(PORT)))
else:
print("USAGE get.py <IP:port> <noeud de départ> <clé>")
if __name__ == '__main__':
main (sys.argv[1:])