ev3/snippets/bluetooth_pc: run client as python3

Even though our main example will have the PC as the server, make it possible to use it as client as well.

Now, it works just like the EV3s. The only difference is that
you must enter the full address instead of the name if the EV3 is the server you are connecting to.
This commit is contained in:
Laurens Valk
2020-05-07 11:56:36 +02:00
parent db10b75808
commit bfe80edff6
@@ -111,12 +111,7 @@ class RFCOMMClient:
self.socket = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)
def handle_request(self):
addr_data = bytearray(sizeof(sockaddr_rc))
addr = struct(addressof(addr_data), sockaddr_rc)
addr.rc_family = AF_BLUETOOTH
str2ba(self.client_address[0], addr.rc_bdaddr)
addr.rc_channel = self.client_address[1]
self.socket.connect(addr_data)
self.socket.connect((self.client_address[0], self.client_address[1]))
try:
self.process_request(self.socket, self.client_address)
except: