can not get lost connection msg?

46 views
Skip to first unread message

sleepd

unread,
Apr 27, 2012, 3:49:55 AM4/27/12
to gev...@googlegroups.com
hi, I am trying to write a server by gevent, and I found that sometimes my server can not got the connection lost signal when client close the connection. this is my code and anyone can help me find out where is the problem?

server runs on Linux, but develop on windows.

def _listener(self, sock):
        while True:
            # gevent will raise a error when connection lost at windows, so use "try"
            try:
                data = sock.recv(1024)
            except socket.error, e:
                break
            if not data:
                break
        self._localServer.lostConnect(self)

Executier Godlike

unread,
Apr 27, 2012, 12:11:57 PM4/27/12
to gev...@googlegroups.com, sle...@gmail.com
May be in this moment recv() returns empty data?
It's the usual approach for socket to indicate closed connections.

cat street

unread,
Apr 27, 2012, 9:04:24 PM4/27/12
to gev...@googlegroups.com
Maybe like this:

    while True:
        try:
            data = sock.recv(1024)
            if not data: break
        except socket.error:
            break


2012/4/27 sleepd <sle...@gmail.com>:
--
HomePage: cat.appspot.com

徐乔

unread,
Apr 27, 2012, 9:47:55 PM4/27/12
to gev...@googlegroups.com
i removed the try and still problem

发自我的 iPhone
Reply all
Reply to author
Forward
0 new messages