Skip to content

fix(windows): fall back to an RFCOMM channel when UUID connect fails - #10

Merged
almasumdev merged 1 commit into
almasumdev:mainfrom
ahmeddhus:fix/windows-rfcomm-channel-fallback
Nov 12, 2026
Merged

almasumdev merged 1 commit into
almasumdev:mainfrom
ahmeddhus:fix/windows-rfcomm-channel-fallback

Conversation

@ahmeddhus

Copy link
Copy Markdown
Contributor

What this changes

On Windows, connect() lets Winsock resolve the service UUID through SDP. With some
devices that resolution fails with WSAEADDRNOTAVAIL (10049), even though the device
is paired and its SPP service works. Windows had created a COM port for it, and a raw
socket on RFCOMM channel 1 connected and printed.

On that error only, connect() now:

  1. retries on the RFCOMM channel an SDP query (WSALookupServiceBegin) reports, then
  2. for SPP only, falls back to channel 1, where serial printers listen.

Other failures (out of range, refused, …) end exactly as before, with no extra wait.
The connectionFailed message now includes the WSA error codes, and its details add
wsaError, so a failure like this one is visible from Dart. The change is limited to
windows/flutter_classic_bluetooth_plugin.cpp, and the Dart API is unchanged.

Platforms touched

  • Android
  • Windows
  • macOS
  • Linux
  • iOS
  • Dart only

How it was tested

Windows 11 (build 26300) with a "Qsprinter" serial thermal printer (it reports vendor
ID 05AC).

  • Before: connecting failed with WSA error 10049 whether secure was true or false.
    The printer was paired, and Windows showed its SPP service as COM4.
  • Raw Winsock check: connecting by the SPP UUID failed with 10049, while a socket on
    RFCOMM channel 1 connected and printed.
  • After: connect() succeeds and the printer prints, from a real app that uses the
    plugin. Discovery and pairing are unchanged.

Checks

  • dart format .
  • flutter analyze reports no issues
  • flutter test passes (214 tests); native Windows tests pass (3/3)
  • CHANGELOG.md updated (as 1.7.4; happy to rename the heading)
  • Capability flags, README support matrix and dartdoc tables still agree (no API change)

Some paired SPP devices make Winsock's own service-class resolution fail
with WSAEADDRNOTAVAIL (10049) although their serial service works. On that
error only, retry on the channel an SDP query reports and, for SPP, on
RFCOMM channel 1. Other failures end as before. The connectionFailed
message now carries the WSA error codes, and its details add wsaError.

Tested on Windows 11 with a serial thermal printer that failed with 10049
before the fix and connects and prints after it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@almasumdev
almasumdev merged commit f172195 into almasumdev:main Nov 12, 2026
10 of 11 checks passed
@almasumdev

Copy link
Copy Markdown
Owner

Thanks a lot @ahmeddhus, this is a great fix. Limiting the fallback to WSAEADDRNOTAVAIL keeps every other failure exactly as it was, and having the WSA code in the error will make the next report like this much easier to diagnose. Testing it on a real printer made it easy to merge.

It's merged and released in 1.7.4, now on pub.dev. The red Android check on this PR came from a Gradle version the newest Flutter no longer accepts, not from your change. That's fixed on main now.

If flutter_classic_bluetooth is useful to you, a star on the repo would be much appreciated. And you're very welcome to send more fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants