sending very large packets over the network

Walker Lindley brotherjenos at gmail.com
Wed Aug 1 18:55:51 EDT 2007


OK, I'm back with another networking question. I'm trying to seend large
amounts of information over TCP (the length of data being given to send() is
on the order of 16000 characters in length). Unfortunately on the receiving
end, the packets appear to be truncated. So I wrote some code that
continuously tries to send bigger and bigger packets until it fails and
noticed that it never fails at the same length. I'm not even sure these two
things are related, but is there some undocumented (or documented and I
missed it) maximum size for data you can pass to send()?

the sample code is as follows
#server
import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("", 2000))
s.listen(0)
sock, addrinfo = s.accept()
for i in range(2 ** 16):
 length = int(sock.recv(16))
 print "excpecting data of length:", length
 data = sock.recv(length)
 print "received data of length:", len(data)
 print
s.close()
sock.close()

#client
import socket
import time

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("", 2001))
s.connect(("localhost", 2000))
for i in range(2 ** 16):
 packet = "h" * i
 s.send("%16d" % len(packet))
 print "attempting to send data of length:", len(packet)
 tmp = s.send(packet)
 print "actually sent data of length:", tmp
 print
 time.sleep(.001)
s.close()

i just put them in different files and ran them from the command line. Any
help or suggestions would be greatly appreciated. Thanks.


-Walker

-- 
This e-mail is licensed under the Creative Commons
Attribution-NoDerivs 2.5License. To view a copy of this license, visit
http://creativecommons.org/licenses/by-nd/2.5/ or send a letter to Creative
Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105,
USA.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070801/46f7ce5c/attachment.html>


More information about the Python-list mailing list