lukeh53 Posted April 3, 2010 Share Posted April 3, 2010 I am working on a science fair project and i am getting frustrated with python. I have two programs, one that receives information from the network that was sent by the other. the one that sends the information is sending the system time, which i got from time.time(), and the second takes that time, and subtracts it from the current time to find how long it took for the data to travel. what frustrates me is the fact that i am getting negative numbers on some runs. here is the code for the programs: this one receives the time: #!/usr/bin/python # Filename: time-server.py import socket, sys, time HOST = ''" PORT = int(sys.argv) s= socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, PORT)) s.listen(1) conn, addr = s.accept() print '[+] Connection from: ', addr while 1: data = float(conn.recv(1024)) if not data: break print '\n[+] Time to send: ', time.time() - data, "\n" conn.close() and this one sends the time: #!/usr/bin/python # Filename: python-client.py import socket, sys, time HOST = 'localhost' PORT = int(sys.argv) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) s.send(str(time.time())) s.close() print '\n[+] Finished\n' any help or direction would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.