Node.py
import socket
import sys
import time
import pp_json as ppjs
import SWATT as sw
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#Get Client IP
client_IP = sock.getsockname()
#Status message for node
status_message = {'Node ID' : 'NS-1', 'Status' : 'Online', 'Node IP' : client_IP }
#Message serialized
ser_clientMsg = ppjs.pp_json(status_message)
#Start Verification variable initialization
flag = '101'
# Connect the socket to the port where the server is listening
server_address = ('localhost', 10100)
print >>sys.stderr, 'connecting to Verifier at %s port %s' % server_address
sock.connect(server_address)
var=1
try:
print >>sys.stderr, 'Sending Node Status "%s"' % ser_clientMsg
sock.sendall(ser_clientMsg)
# Send data
while var:
recvData = sock.recv(256)
print >>sys.stderr, 'Received from Verifier: "%s" \n' % recvData
if recvData == flag:
print "Starting verification process...\n"
filename = "hello.txt"
fh = open(filename,"r")
temp_str = fh.read()
checksum = sw.SWATT(temp_str, len(temp_str))
sock.sendall(checksum)
finally:
print >>sys.stderr, 'closing socket'
sock.close()
Verifier.py
import socket
import sys
import time as t
import json
startTime = t.time()
#Count variable initialization
count = 0
#Send Start Verification Prompt
start_verif = '101'
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#Bind the socket to the port
server_address = ('localhost', 10100)
print >>sys.stderr, 'Starting Verifier on %s port %s' % server_address
sock.bind(server_address)
#Listen for incoming connections
sock.listen(1)
while True:
#Wait for connection
print >>sys.stderr, 'Waiting for connection establishment'
connection, client_address = sock.accept()
try:
print >>sys.stderr, 'Connection from', client_address
#Receive the data in chunks and retransmit it
while True:
if count == 0:
statusData = connection.recv(256)
parsedData = json.loads(statusData)
#print >>sys.stderr, 'Received "%s"' % parsedData
print "Received Node Status: \n", json.dumps(parsedData, indent=4, sort_keys=True)
count+=1
elif count == 1:
print 'Sending Verification Trigger:\n', start_verif
connection.sendall(start_verif)
count+=1
checksum = connection.recv(256)
print "Checksum value from Prover: ", checksum
print "\n"
else:
print >>sys.stderr, 'SWATT successfully computed on Node with Node address: ', client_address
finally:
elapsedTime = t.time() - startTime
print elapsedTime
connection.close()
Я думаю, проблема в строке 37 в Node.py, так как я могу видеть значение 101, напечатанное изпредыдущая строка, которая является строкой 36 на терминале узла.Можете ли вы помочь мне найти, где именно ошибка.Также, пожалуйста, прокомментируйте, если вам нужны коды модулей, которые я импортировал.Я буду рад опубликовать их позже.