Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket has not been initialized when calling rawBytes method #172

Open
nerahmou opened this issue May 2, 2023 · 0 comments
Open

Socket has not been initialized when calling rawBytes method #172

nerahmou opened this issue May 2, 2023 · 0 comments

Comments

@nerahmou
Copy link

nerahmou commented May 2, 2023

I got this error sometimes when calling printer.rawBytes(buffer).
Looking at the source code, I don't understand how socket has not been initialized if connect result is success.

Package code :

Future<PosPrintResult> connect(String host,
      {int port = 91000, Duration timeout = const Duration(seconds: 5)}) async {
    _host = host;
    _port = port;
    try {
      _socket = await Socket.connect(host, port, timeout: timeout);
      _socket.add(_generator.reset());
      return Future<PosPrintResult>.value(PosPrintResult.success);
    } catch (e) {
      return Future<PosPrintResult>.value(PosPrintResult.timeout);
    }
  }

My code :

final PosPrintResult result = await _networkPrinter.connect(ipAddress, port: 9100);

if (result == PosPrintResult.success) {
 _networkPrinter.rawBytes(_buffer);
      _networkPrinter.cut();
      _networkPrinter.disconnect();
    }
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

No branches or pull requests

1 participant