×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Dec 2008
    Location
    Germany
    Posts
    11

    Reading socket in thead

    Hi,

    I'm rellay frustrated right now. Everytime I try to do something in a thread it doesn't work or the whole application freezes!

    Here I tried to read out an incoming string from a PC over Bluetooth in a thread:

    Code:
    #
    #   Press "1" for sending messages!
    #
    import appuifw, socket, e32, thread, key_codes
    
    ECHO = True
    args= "",""
    
    def choose_service(services):
        names = []
        channels = []
        for name, channel in services.items():
            names.append(name)
            channels.append(channel)
        index = appuifw.popup_menu(names, u"Choose service")
        return channels[index]
    
    def readInStream(e1,e2):
        while True:
            global to_peer, conn
            reply = conn.recv(4096)
            if reply:
                appuifw.note(unicode(reply), "info")
    
    address, services = socket.bt_discover()
    channel = choose_service(services)
    conn = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
    conn.connect((address, channel))
    
    
    def send():
        global to_peer, conn
        msg = appuifw.query(u"Send a message", "text")
        if msg:
            conn.send(msg + "\r\n")
    
    canvas = appuifw.Canvas()
    appuifw.app.body = canvas
    canvas.bind(key_codes.EKey1, send)
    
    thread.start_new_thread(readInStream, args)
    hold = e32.Ao_lock()
    hold.wait()
    to_peer.close()
    conn.close()
    Has anybody an idea how to get the thread working?!?

  2. #2
    Super Contributor
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744

    Re: Reading socket in thead

    Hi Slowmoe,

    If I'm not wrong, the arguments you pass in the thread should be between parenthesis. So it would be like this:

    Code:
    thread.start_new_thread(readInStream, (args))
    Just test this there and tell me what you got


    Hope it helps,

    Rafael.

  3. #3
    Registered User
    Join Date
    Dec 2008
    Location
    Germany
    Posts
    11

    Re: Reading socket in thead

    Hi Rafael,

    thx for your answer.

    I'm at work right now, but I'll test it this evening!

    If this is the failure I tink I'll have a fit!

  4. #4
    Regular Contributor
    Join Date
    Jan 2004
    Location
    Helsinki
    Posts
    376

    Re: Reading socket in thead

    Quote Originally Posted by Slowmoe View Post
    Hi Rafael,

    thx for your answer.

    I'm at work right now, but I'll test it this evening!

    If this is the failure I tink I'll have a fit!
    Socket object must be created in the thread it is used.

    For thread debugging tips see this example application http://bazaar.launchpad.net/~pys60co...7in81mt9gmhv-6
    Mikko Ohtamaa

    http://mfabrik.com
    http://blog.mfabrik.com

  5. #5
    Registered User
    Join Date
    Dec 2008
    Location
    Germany
    Posts
    11

    Re: Reading socket in thead

    Quote Originally Posted by miohtama View Post
    Socket object must be created in the thread it is used.

    For thread debugging tips see this example application http://bazaar.launchpad.net/~pys60co...7in81mt9gmhv-6

    Hi,
    thx for the hint! This sounds like there is no solution to read and write permanently with one stable connection as in J2ME!?!?

    The szenario is the following:
    The user should establish one permanent connection to pc when the application starts. The application sends permanently data to the socket. Besides it should be possible to read out data from this connection at specific moments in time without creating a new connection and without blocking the whole application.

    Any ideas?

  6. #6
    Super Contributor
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744

    Re: Reading socket in thead

    Quote Originally Posted by Slowmoe View Post
    Hi,
    thx for the hint! This sounds like there is no solution to read and write permanently with one stable connection as in J2ME!?!?

    The szenario is the following:
    The user should establish one permanent connection to pc when the application starts. The application sends permanently data to the socket. Besides it should be possible to read out data from this connection at specific moments in time without creating a new connection and without blocking the whole application.

    Any ideas?
    Hi Slowmoe,

    You can check this example about exchanging data between two devices using bluetooth



    Hope it helps,

    Rafael.

  7. #7
    Registered User
    Join Date
    Dec 2008
    Location
    Germany
    Posts
    11

    Re: Reading socket in thead

    Hi,

    thx for the example!
    This e32.ao_callgate() could be usefull!

    By the way...I tried to draw an incoming string (from socket) on the mobile display.
    I've seen that the string implements special signs at the end (maybe a signal for end of the incoming string).

    It looks like "Helloםםם". Does anybody know how to cut these signs?

    Thx!

  8. #8
    Regular Contributor
    Join Date
    Jan 2004
    Location
    Helsinki
    Posts
    376

    Re: Reading socket in thead

    Quote Originally Posted by Slowmoe View Post
    Hi,

    thx for the example!
    This e32.ao_callgate() could be usefull!

    By the way...I tried to draw an incoming string (from socket) on the mobile display.
    I've seen that the string implements special signs at the end (maybe a signal for end of the incoming string).

    It looks like "Helloםםם". Does anybody know how to cut these signs?

    Thx!
    Probably unicode problem. Convert all strings to unicode prior rendering them on Series 60. draw_string(unicode(mydata))

    Also you can use text renderer class:

    http://bazaar.launchpad.net/~pys60co...7in81mt9gmhv-8
    Mikko Ohtamaa

    http://mfabrik.com
    http://blog.mfabrik.com

Similar Threads

  1. S60 - C++ - Socket Client - Reading SMS in Binay from InBox and Write to a socket?
    By www_peach in forum Symbian Networking & Messaging (Closed)
    Replies: 8
    Last Post: 2006-02-01, 02:57
  2. problem in persistant socket connection
    By poms4symbian in forum Browsing and Mark-ups
    Replies: 0
    Last Post: 2006-01-03, 13:23
  3. Replies: 0
    Last Post: 2005-09-20, 03:58
  4. S60 - C++ - Socket Client - Reading SMS in Binay from InBox and Write to a socket?
    By www_peach in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2005-09-20, 03:56

Posting Permissions

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