×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Sep 2008
    Location
    Turkiye
    Posts
    32

    Sending tuples via bluetooth?

    hi everybody
    lately im working on an exciting project
    but i got a problem about about sending two variables at same time via bluez module
    therefore,i need to send these two variables as a tuple object , i guess

    infact i found a way send two variables at same time as string but it's too laggy and sometimes causing errors
    here is my solution which is so laggy:
    on client:
    def senderfunction():
    socket.send(str(a)+' '+str(b))
    on server:
    a=int(incomingdata[0:3])
    b=int(incomingdata[4:len(incomingdata)]

    variable a and b are numbers between -99 and +99
    please help

  2. #2
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: Sending tuples via bluetooth?

    Hello McLightning, welcome "a discussion board"

    Suggestions, following your initial approach (I am supposing that a and b are numbers):

    Sender:

    Code:
    msg = "%d %d" % (a,b) # space is the field delimiter !
    sock.send(msg)
    Decoding at receiver:

    Code:
    msg = msg.split() # space is the field delimiter !
    a = int(msg[0])
    b = int(msg[1])
    However, take care when receiving, ensure recv got all expected bytes. socket.makefile() is available for TCP/P sockets. If it is available for bluetooth sockets as well I recommend to use it instead recv/send since you will have a better flow control for text oriented messages.

    If you want something more sophisticated, I recommend simplejson. Using simplejson you can serialize complete objects instead only string. You will find a example in the thread.

Similar Threads

  1. Problem in sending DRM file over Bluetooth..?
    By sumit_rusia in forum Digital Rights Management & Content Downloading
    Replies: 2
    Last Post: 2007-08-21, 07:08
  2. Sending List Objects using Bluetooth
    By seanmcgowan in forum Mobile Java General
    Replies: 6
    Last Post: 2007-03-19, 14:37
  3. Replies: 0
    Last Post: 2005-12-10, 00:42
  4. Sending List Objects using Bluetooth
    By seanmcgowan in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2004-11-01, 15:12
  5. Sending large data via Bluetooth sockets
    By yellow27 in forum Bluetooth Technology
    Replies: 0
    Last Post: 2003-12-18, 03:59

Posting Permissions

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