mrtazz (owner)

Revisions

gist: 225486 Download_button fork
public
Public Clone URL: git://gist.github.com/225486.git
Embed All Files: show embed
simple_tcp_client.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
import socket
import time
 
HOST = 'localhost' # The remote host
PORT = 9999
MSGLEN = 100 * 1000 * 1000
# create the socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# connect to host and port
s.connect((HOST, PORT))
# say what the server should send
s.send('Stuff to send')
msg = ''
starttime = time.time()
# initialize counter
counter = 0
# get the message in chunks
while len(msg) < MSGLEN:
    chunk = s.recv(1000)
    msg = msg + chunk
    #print len(chunk)
    #print "Packet counter: %d" % counter
    counter += 1
print len(msg)
s.close()
endtime = time.time()
print (endtime - starttime)