×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    2

    UI and bluetooth server and client, all within one app

    My application involves the creation of bluetooth server and client sockets, as well as a UI, all within the same application. I would like to run the bluetooth server and client sockets as their own separate respective threads. The server and client sockets are implemented in their own classes and own their own locks. They will not share any data between them, but rather will read and write to a database (implemented using e32db). However, what I have written so far always blocks on the server_socket.accept() method. The server and client socket threads are started in the following way:

    Server:

    Code:
    def run(self):
    	# Dummy run program for right now
    	while 1:
    		self.lock.acquire()
    		clientSocket, clientAddress = self.serverSocket.accept()
    		# do some stuff
    		clientSocket.close()
    		self.lock.release()
    Client:

    Code:
    def run(self):
    	# Dummy run program for right now
    	while 1:
    		self.lock.acquire()
    		self.clientSocket.connect((serverAddress, serverPort))
    		# do some sending and receiving
    		self.clientSocket.close()
    		self.lock.release()
    And I start the threads as follows, from within the UI thread:

    Code:
    thread.start_new_thread(clientObject.run, ())
    thread.start_new_thread(serverObject.run, ())
    From what I understand I can use select() on sockets that are already connected. However, in the server socket, the accept() method blocks all other threads; I am not able to exit out of python, but I am able to switch to the telephone functions of the phone (indicating to me, at least, that the telephone thread is running at a higher priority of my own threads, which is probably a good thing!). I have to do a hard restart of the phone to kill Python (i.e., removing the battery).

    What I would like to do is to be able to run the server and client threads in the background in the context of a UI program. My application is an ad-hoc bluetooth networking system where each phone can server as a send and receive node. I realize I could simply make the client and server threads separate applications; the reason to do all of this within one application is because of my target users, as they may not have the technical-know how to start multiple applications and keep them running, but I _am_ able to tell them how to start one application and leave it running in the background.

    Thanks for your help, and let me know if there is anything I might be missing, or any other clarification I need to make!

    nick

  2. #2
    Registered User
    Join Date
    Nov 2007
    Posts
    2

    Re: UI and bluetooth server and client, all within one app

    I hate to be that person who bumps his own thread, but just curious if anyone has thoughts as to this problem. A simple "it's easy, just work on it more!" or "it's impossible, give up and split up the server and the client" would be fine

    thanks!

Posting Permissions

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