title: How to prevent socket timeout error when printing to ESC/POS with Flutter
body: <p>I am using the <code>Flutter</code> package <code>esc_pos_printer 1.5.0</code> to print to a thermal receipt printer. It works fine if the printer is online but I get a socket timeout when it is not, even when I nest the code in a try / catch block. </p>
  
  <p>Normally I expect the printer will be connected by Ethernet but it could also be WiFi.</p>
  
  <p>The package author recommends using <code>andrey-ushakov/ping_discover_network</code>
   but that package says in the <code>README</code></p>
  
  <blockquote>
    <p>Could be used to find printers (for example, on port 9100) and any
    other devices and services in local network.</p>
    
    <p>The device should be connected to a Wi-Fi network. wifi package allows
    to get the local IP address / network subnet.</p>
  </blockquote>
  
  <p>Here is the error:</p>
  
  <blockquote>
    <p>ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception:
    SocketException: OS Error: Connection timed out, errno = 110</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <pre><code>  try {    
  
      Printer.connect('192.168.1.100', port: 9100).then( (printer) {
  
        printer.println('welcome',
          styles: PosStyles(
            height: PosTextSize.size2,
            width: PosTextSize.size2,
          ));
  
        printer.cut();
        printer.disconnect();
        }
      );
      }    
      catch (e) {    
        print(e);
        // do stuff
      }  
    }
  </code></pre>