import socket import os port = 60000 s = socket.socket() host = socket.gethostname() s.bind((host, port)) s.listen(5) print 'Server listening....' while True: conn, addr = s.accept() print 'Got connection from', addr data = conn.recv(1024) print('Server received', repr(data)) filename='akki.txt' b = os.path.getsize(filename) f = open(filename,'rb') l = f.read(b) while (l): conn.send(l) l = f.read(b) f.close() print('Done sending') conn.send('Thank you for connecting') conn.close()
import socket import time import os s = socket.socket() host = socket.gethostname() port = 60000 t1 = time.time() s.connect((host, port)) s.send("Hello server!") with open('received_file', 'wb') as f: print 'file opened' t2 = time.time() while True: data = s.recv(1024) if not data: break f.write(data) t3 = time.time() print data print 'Total:', t3 - t1 print 'Throughput:', round((1024.0 * 0.001) / (t3 - t1), 3), print 'K/sec.' f.close() print('Successfully received the file') s.close() print('connection closed')
print 'Throughput:', round((1024.0 * 0.001) / (t3 - t1), 3),
print 'Throughput:', round((totalbytesreceived * 0.001) / (t3 - t1), 3),
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)