From test, i concluded that in following three cases the socket.recv(recv_size) will return.
- 1) After the connection was closed(for example, the client side called socket.close()) or any socket error occurred, it would return empty string.
- 2) Some data come, the size of data is more than recv_size.
- 3) Some data come, the size of data is less than recv_size and no more data come after a short time(i found 0.1s would work)?
More details about 3):
#server.py
while True:
data = sock.recv(10)
print data, 'EOF'
#client1.py
sock.sendall("12345")
sock.sendall("a" * 50)
#client2.py
sock.sendall("12345")
time.sleep(0.1)
sock.sendall("a" * 50)
When i run client1.py, the server.py echos:
12345aaaaa EOF
aaaaaaaaaa EOF
aaaaaaaaaa EOF
aaaaaaaaaa EOF
aaaaaaaaaa EOF
aaaaa EOF
When i run client2.py, the server.py echos:
12345 EOF
aaaaaaaaaa EOF
aaaaaaaaaa EOF
aaaaaaaaaa EOF
aaaaaaaaaa EOF
aaaaaaaaaa EOF
Is my conclusion correct? Where can i see the official description about 3)?
http://stackoverflow.com/questions/7174927/when-does-socket-recvrecv-size-return
Some related knowledge:
docs.python.org/library/socket.html#socket.socket.recv
http://linux.die.net/man/3/recv
http://gnosis.cx/publish/programming/sockets.html
socket.setblocking(flag)
Set blocking or non-blocking mode of the socket: if flag is 0, the socket is set to non-blocking, else to blocking mode. Initially all sockets are in blocking mode. In non-blocking mode, if a recv() call doesn’t find any data, or if a send() call can’t immediately dispose of the data, a error exception is raised; in blocking mode, the calls block until they can proceed. s.setblocking(0) is equivalent to s.settimeout(0); s.setblocking(1) is equivalent to s.settimeout(None).
呵呵,谢谢
VaTG790i.最好的<a href=http://www.kyfei.com>网站推广软件</a>,
非常好
....................
;ui;普i;uighur;ui;ui;个
在unix网络编程中看到了关于TCP/IP的一些内容,我感觉还是写的不够。正在下载中,一定
下载地址呢