I can't work out how to get the client.py and server.py files to run at the same time to establish the Bluetooth connection and transfer data from the server to the client.
I've started writing an android app using kivy, and I need it to lookup a file on a host computer. I've written a client.py and a server.py file to try and establish the Bluetooth connection, and then send the file from the server to the client by reading it and sending the contents as a dictionary.
I'm sorry, I'm a complete newby and this is probably very bad.
Client:
from bluetooth import *
server_addr = "xx:xx:xx:xx:xx:xx"
port = 1030
sock = BluetoothSocket(RFCOMM)
sock.connect((server_addr, port))
while True:
response = sock.recv(1024)
if len(response) == 0:
break
print("received [%s]" % response)
Server:
from bluetooth import *
server_sock = BluetoothSocket(RFCOMM)
port = 1030
server_sock.bind(("xx:xx:xx:xx:xx:xx",port))
server_sock.listen(1)
client_sock,address = server_sock.accept()
print("Accepted connection from ", address)
f = open("database.txt", "r")
listOfUsers = {}
for line in f:
email, password, firstName, lastName = line.strip().split(",")
listOfUsers[email] = (password, firstName, lastName)
f.close()
server_sock.send(listOfUsers)
client_sock.close()
server_sock.close()
I have been trying to run both files on the computer to test them, but I have no idea if they work, as when I run them both from the command prompt in Windows the python terminal just pops up and closes again, without doing anything. Even if they did work, I still don't know how I would get them both to run with the client file being in the app and the server file on the computer.
Thank you for trying to help and being patient with me!