Search code examples
pythonbluetoothmobile-phones

Send a file between 2 mobile phones via bluetooth using Python


I am trying to send a file between two mobile phones using Python language

for the phone that will send i used this code:

import socket,e32socket,appuifw
socket=e32socket.socket(e32socket.AF_BT,e32socket.SOCK_STREAM,e32socket.BTPROTO_RFCOMM,e32socket.OBEX)
device =e32socket.bt_obex_discover()
print device
address=device[0]
print address
channel=device[1][u'OBEX Object Push']
print channel
e32socket.bt_obex_send_file(address,channel,u"E:23.txt")

for the mobile that will receive i used this code

import socket,e32socket,appuifw
socket=e32socket.socket(e32socket.AF_BT,e32socket.SOCK_STREAM,e32socket.BTPROTO_RFCOMM,e32socket.OBEX)
e32socket.bt_obex_receive(socket, u"E:23.txt")

I savesd first code in .py in an moible then i excuted using python interpreter,, first the bluetooth discovery menu appeares then i selected a mobile that has the mac address which is in the first code,, the error in the last line in that code ""socket.error:(2,'No such file or directory') "" this the error which i found

Can someone help me to solve this problem?


Solution

  • For one, "E:23.txt" is not a valid path to a file. Always remember your slashes, they are very important! Thus, you would change it from:

    e32socket.bt_obex_send_file(address,channel,u"E:23.txt")
    

    to

    e32socket.bt_obex_send_file(address,channel,u"E:\\23.txt")
    

    Also, I am not quite familiar with bt_obex_receive, but you would want to fix that path as well.

    Additionally, you are importing the appuifw module without using it. Unless you plan on adding code that uses it, importing it is very inefficient.