Skip to content
Advertisement

Why i get error using accept() method in pybluez?

I wanna make a simple connection between raspberry and phone but every time i write .accept() i get [Errno 77] File descriptor in bad state. Here is the code:

JavaScript

Advertisement

Answer

The problem is that you mixed up both client and server logic in the given code snippet. Once connect() is called the socket becomes a client, so indeed trying to call accept() after that would fail. Simply remove client, badr = s.accept() to make the client side work.

Below is an example of the client side implementation:

JavaScript

and here is an example of the server side implementation:

JavaScript

You can run server() on the raspberry and client() on the phone, or vice versa.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement