I want to use twisted and bluetooth together. At the moment I am doing this with PyBluez running in an twisted thread.
PyBluez just creates some socket (or socket-like? it has a file descriptor like a normal socket) object, basically you do:
sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
sock.connect((device_id,1))
Can't I just insert that socke开发者_StackOverflow中文版t into the twisted reactor somehow and connect it with a Protocol?
You can write a class implementing IReadDescriptor (or IWriteDescriptor) and connect it to reactor, like in this example.
I found this project which combines pybluez with twisted: http://pydoc.net/airi/0.1.1/airi.twisted_bluetooth
This piece of code actually helped me a lot. I now have a working implementation in Twisted.
精彩评论