×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    386

    select.select() with server sockets

    Hi,

    recently I was trying some IPC using sockets on my phone (6600). I wrote two scripts (server and client) and run one from my Ped and the other one from the standard Python Shell.

    The server was using port 39871 (arbitrary one) on host 127.0.0.1 (localhost).

    It worked quite well until I've tried the select module.

    It seems that you cannot use select for waiting for incoming connections. So if your socket is a listening one and you're calling select() because you don't know if accept() will block (you do it by passing timeout=0 to the select), you can't do that. I haven't found anything about this limitation in PyS60 docs.

    Here's a part of the server code:
    Code:
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.bind(('127.0.0.1', 39871))
    sock.listen(3)
    
    lst = select.select([sock], [], [])[0]

    Oddly, when it gets to the select line, it dumps
    Code:
    error socket.error (0, 'Error')
    to the stdout or stderr (although I haven't print anything).

    Then it continues the execution.

    After the socket has been connected/accepted, select works as expected.

    Should I file a bug report?

    Kind regards,
    yak
    Last edited by y.a.k; 2007-10-22 at 14:31.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    386

    Re: select.select() with server sockets

    I've found a temporary solution to this problem.

    Looking at the PyS60 socket.py module revealed that socket methods like connect, send, recv and accept have an undocumented cb (callback) argument.

    Here's an example:
    Code:
    def accept_callback((s, addr)):
        # s is the new socket (e32socket.Socket type), addr the address it was connected from
        print s, addr
    
    socket.accept(accept_callback)
    This doesn't allow you to test if there are awaiting connections but you don't need a separate thread for accept() if you want to do other things in the meantime. Callbacks are most probably based on Active Objects so they will only be called if you're in e32.ao_sleep(), e32.Ao_lock().wait() or such thing.
    Last edited by y.a.k; 2007-10-22 at 16:12.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    5

    Re: select.select() with server sockets

    is it possible to use this e32.socket in select()?

    it raises a NotImplemented exception, because it is no socket.socket..

    --edit--
    using
    Code:
    socket._socketobject(s, socket.AF_INET)
    helps
    --/edit
    Last edited by flx013; 2007-12-10 at 14:40.

Similar Threads

  1. Replies: 12
    Last Post: 2007-09-27, 13:07
  2. Server sockets
    By jhnwkmn in forum Open C/C++
    Replies: 1
    Last Post: 2007-04-12, 11:13
  3. Server on emulator doesnt recv via sockets
    By kilokahn2 in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2004-10-27, 08:05
  4. How to bind UDP server sockets?
    By mimo099 in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2004-10-15, 19:31
  5. How to use the sockets example connect to an external socket server
    By jgszz in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2002-12-10, 14:37

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×