Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Weird socket problem

Name: Anonymous 2011-01-15 1:57

/prog/ I come to you for help with my superior ENTERPRISE(tm) programming.

The test environment is Windows XP running under VirtualBox and I'm using Python to execute the program.

Basically I want to send n amount of data with socket.send and have a reliable estimate on how long it has taken to send n bytes. I am using sockets with a timeout of 15 seconds. Let me explain in my own words why I haven't been able to do what I want:

Apparently send works with network buffers. It just adds what I'm trying to send to the network buffer and returns the amount of data it passed to this buffer, only ever blocking/sleeping when the buffer is full. So in other words, send doesn't actually send anything. So even when I send large amounts of data, 100MB or more, send returns instantly, WTF.

Shouldn't the buffer be a reasonable size, and if send really does work like this how am I to determine how many bytes have been actually sent?

Note: I don't want to use a protocol, i.e. have the client return how many bytes received because I'm working on a socket class.

Note: I don't have this problem with recv it seems . . .

Please help me /prog/, no troll.

Name: Anonymous 2011-01-15 23:29

Look at this /prog/:

[quote]
python test.py
Send buffer size (sock.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF)) 16384
time.clock() 0.04
sent: 115928 bytes
time.clock() 0.04
[/quote]

Shitty test code I wrote specifically to demonstrate the issue:

import socket
import time
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
print "Send buffer size (sock.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF))", sock.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF)
sock.connect(("www.google.com", 80))
#buf = "GET /dicks.html HTTP/1.1\r\n"
#buf += "Host: www.google.com\r\n\r\n"
buf = "x" * ((1024 * 1024) * 10)
print "time.clock()", time.clock()
print "sent:", sock.send(buf), "bytes"
print "time.clock()", time.clock()
sock.close()


Now am I right in assuming the maximum amount of data send should be able to send each call is the same amount returned from sock.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF) and if so why are the results different.

Look at this log file I found online for example which is very similar to my code:
[quote]
0811 15:58 chronis:~% python !$
python scratch/sendtst.py
connected from ('208.210.124.49', 1258)
sent 17520/10000000 chars
done
0811 15:58 chronis:~%      
[/quote]
You see here it sent an amount very close to the size of my send buffer!

Here is his code:

import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect("chronis.pobox.com", 8010)
sent = sock.send(s)
if sent != len(s):
    print "sent %d/%d chars" % (sent, len(s))
else:
    print "sent all chars"


I am losing my mind.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List