Hi,

Could anyone clarify on how to connect to the phone over RFCOMM using python? I'm sure this is meant to be easy but for some reason my python code on the phone does not receive the connection from the PC. My phone code looks like this: (borrowed from the other thread talking about the socket._sock bug)


from socket import *
s = socket(AF_BT, SOCK_STREAM)
p = bt_rfcomm_get_available_server_channel(s._sock)
s.bind(("", p))
bt_advertise_service( u"asdf", s._sock, True, RFCOMM)
set_security(s._sock, AUTHOR)

print 'Listening...'
s.listen(1)
print 'After Listening'
conn, addr = s.accept()
print "connected to", addr
data = conn.recv(1)


Then I connect to the phone from my PC using PySerial, connecting to COM4. The code on the phone never receives the connection: it gets as far as to print the 'After Listening' message but it never receives a connection to print the "connected to" message. But, and I found this weird: I don't think I'm connecting to the wrong COM port, because the phone still comes up with the "do you want to accept the connection from <me>?" prompt.

So it seems the connection is getting to my phone, but not my python code? This seems confirmed by the fact my code is using AUTHOR so it should authorize incoming connections but when I connect, it still prompts for authentication.

My PySerial code is very simple, just:


import serial
ser = serial.Serial(3)
# after the above line, the phone pops up the authentication message
ser.write("hello")
# now the code will just hang, I guess it has nothing at the other end to write to?


Thanks very much if anyone can help, it would be greatly appreciated.


(On another note, can OBEX files be sent from the PC to the phone using python? Can a file object be somehow wrapped into an OBEX object?)