×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    26

    Question with socket.recv()

    Hello ,
    I always seem to come to a problem . My problem is in the RFCOMM, the server receives while the client accepts. Problem accures when the client cancels the program which makes the server crash. the server is:
    data1= socket.recv()

    My question is, is there a way to make the program continue and start from the while loop again instead of crashing?
    The server code temp is like so:

    Code:
    #imports modules here
    
    while (1):
         server_socket=socket(AF_BT, SOCK_STREAM)
         # Rest of RFCOMM code here
         data1= socket.recv(1024)
         if not data1: break
         # rest of code
         sock.close()
         server_socket.close()
    Thank you

  2. #2
    Regular Contributor
    Join Date
    Apr 2009
    Posts
    65

    Re: Question with socket.recv()

    Doesn't exception handling help?
    http://croozeus.com/blogs/?p=983
    --NirpSis

    http://sites.google.com/site/nirpsis/
    http://nirpsis.blogspot.com/

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    26

    Re: Question with socket.recv()

    Can you correct me if am doing this wrong, I am using this example to test the try and exception
    Code:
    from socket import *
    import appuifw
    
    server = socket(AF_BT, SOCK_STREAM)
    p = bt_rfcomm_get_available_server_channel(server)
    server.bind(("", p))
    print "bind done"
    server.listen(1)
    bt_advertise_service( u"Tester", server, True, RFCOMM)
    set_security(server, AUTH)
    (sock,peer_addr) = server.accept()
    print "Connection from %s"%peer_addr
    try:
         data = sock.recv(1024)
    except server_socket.error:
         sock.close()
         return
    print "Received text done"
    sock.close()
    The exception should be done to the receiving file or the socket connection? And why does this code give an error when executed?
    Code:
    while True:
        datas = ""
        data = sock.recv(1024)
        if not data:
            break
        datas = datas+data
    Thank you

Similar Threads

  1. Annoying question when dialing by bluetooth
    By tejohf in forum Bluetooth Technology
    Replies: 0
    Last Post: 2003-09-04, 19:56
  2. Newbie question: What is the call stack?
    By advocatee in forum Symbian
    Replies: 2
    Last Post: 2003-06-22, 05:27
  3. Replies: 1
    Last Post: 2003-04-14, 03:14
  4. Replies: 0
    Last Post: 2003-04-07, 09:52
  5. question deleted
    By kiokups in forum General Messaging
    Replies: 1
    Last Post: 2002-09-25, 20:07

Posting Permissions

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