import socket import hmac import hashlib import time #Simply change the host and port values host = '192.168.1.138' port = 8888 secretKey = 'j344rfdas' s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) def create_packet(klient_id, even_id, request): timest = (int(time.time())) # print("\n aeg on: ", timest, "\n") packet = "{}.{}.{}.{}.{}".format(klient_id, even_id, timest, request, bytes.decode (hashpacket("{}.{}.{}.{}".format(klient_id, even_id, timest, request)))) global requ requ = "{}.{}.{}.{}".format(klient_id, even_id, timest, request) return packet def hashpacket(packet): bytes = str.encode(packet) key = str.encode(secretKey) print(key) print(bytes) hashedpacket = ( hmac.HMAC(key, bytes,hashlib.sha256)) global origkey origkey = hashedpacket.hexdigest() return str.encode(hashedpacket.hexdigest()) alfa = (create_packet(123,4,"Open")) print(alfa) def saada(pakett): try: s.connect((host, port)) # s.shutdown(2) print("Success connecting to ") print(host," on port: ",str(port)) data = str.encode(pakett) print ("sending :", pakett) s.sendall(str.encode(pakett)) tagasi = (s.recv(2048)) print (tagasi) # s.send(bytes) except socket.error as e: print("Cannot connect to ") print(host," on port: ",str(port)) print(e) saada(alfa)