I try to build computer program that trasfer files use Bluetooth and OBEX technology between Windows and RPI. I use BLuetooth RFCOMM Server @ Windows Side. RPI is @ client side. I use pybluez and PyObex for both side. Now I sent file from RPI side. However I can't catch the file @ Windows side. Code elements figured at below.

Server Side:

class BlueDev(object):
    def __init__(self):
        self.socket = BluetoothSocket(RFCOMM)
        self.server = BrowserServer()
        self.port = None
    def startService(self):
        """ Starts Socket and Advertising Service """

        self.port = self.socket.getsocketname()[1]
        self.server.start_service(self.socket) ## advertise server
        self.server.serve(self.socket) ## accepts connection
if __name__ == "__main__"
    blueDevServ = BlueDev()

Client Side:

class BluetoothDev(object):
    def __init__(self):
        self.client = None
        self.socket = Bluetooth(RFCOMM)
        self.port = None
        self.address = ""
    def startService(self):
        if sys.version < '3':
            input = raw_input
        if len(sys.argv) < 2:
            print("No device")
        services = bluetooth.find_service(uuid=OBEX_FILETRANS_CLASS, address=self.address)
        servicesMatch = services[0]
        port = servicesMatch["port"] 
        self.address = servicesMatch["host"]
        print(port , self.address)
        self.client = client.BrowserClient(self.address,port)
        print("Client is ready")
    def connect(self):
        print "Connected from client Side"
if __name__ == "__main__":

    blueClient = BluetoothDev()
    devices = blueClient.discover()
    print("Waiting for server service")
    client.put('test.txt', 'HelloWorld!')
    print("File Sent:")

I couldn't find missing elements on architecture.How can i catch sent files on Server Side?

  • I solved file transfer process without OBEX. I used basic socket to data transfer. After accept connection @ServerSide:
    – AgE
    Commented Oct 26, 2015 at 14:40

1 Answer 1


I solved the problem without OBEX. I used socket's recv() and send(). After accept connection @ServerSide

def sendFile(self ,sendPath,packageSize):
    Sends file to the device
    @param sendPath is file path address @ host device
    @param packageSize is packet size of pure data @BluetoothSocket
    if (packageSize == None):
        packageSize = 1024
    f = open(sendPath,'rb')
    self.clientSocket.send(sendPath)##send EXACT name of file 
    packet = 1
    print(sendPath ,"is", os.pat.getsize(sendPath), "starts @", time.ctime())
    while (packet):
        packet = f.read(1024)
    print("Send @:", time.ctime())
    isFileSent = True

@ClientSide after accept() from server side:

def getFile(self, gotPath, packageSize):
    Collects arriving packets
    if (packageSize == None):
        packageSize = 1024
    name = self.socket.recv(packageSize)
    f = open(name, wb)
    packet = 1
    while packet:
        packet = self.socket.recv(packageSize)
    self.isFileGot= True
    print ("File GOT")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.