title: How can i connect to TCP socket (not web socket) in flutter?
body: <pre><code>import 'dart:typed_data';
  import 'package:flutter/foundation.dart';
  import 'dart:io';
  import 'package:flutter/material.dart';
  
  void main() async {
  
    Socket sock = await Socket.connect('192.168.1.150', 2662);
    print('Connected to: ${sock.remoteAddress.address}:${sock.remotePort}');
    runApp(MyApp(sock));
    sock.listen(
         
          (Uint8List data) {
        final serverResponse = String.fromCharCodes(data);
        print('Server: $serverResponse');
      },
      
      onError: (error) {
        print(error);
        sock.destroy();
      },
  
      onDone: () {
        print('Server left.');
        sock.destroy();
      },
    );
  }
  
  class MyApp extends StatelessWidget {
    Socket socket;
  
    MyApp(Socket s) {
      this.socket = s;
      s.listen(
  
            (Uint8List data) {
          final serverResponse = String.fromCharCodes(data);
          print('Server: $serverResponse');
        },
  
        // handle errors
        onError: (error) {
          print(error);
          s.destroy();
        },
  
        onDone: () {
          print('Server left.');
          s.destroy();
        },
      );
    }
  
    @override
    Widget build(BuildContext context) {
      final title = 'Example';
      return MaterialApp(
        title: title,
        home: MyHomePage(
          title: title,
          channel: socket,
        ),
      );
    }
  }
  
  class MyHomePage extends StatefulWidget {
    final String title;
    final Socket channel;
  
    MyHomePage({Key key, @required this.title, @required this.channel})
        : super(key: key);
  
    @override
    _MyHomePageState createState() =&gt; _MyHomePageState();
  }
  
  class _MyHomePageState extends State&lt;MyHomePage&gt; {
    TextEditingController _controller = TextEditingController();
  
    @override
    Widget build(BuildContext context) {
  
      return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: Padding(
          padding: const EdgeInsets.all(20.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: &lt;Widget&gt;[
              Form(
                child: TextFormField(
                  controller: _controller,
                  decoration: InputDecoration(labelText: 'Send a message'),
                ),
              ),
              StreamBuilder(
                stream: widget.channel,
                builder: (context, snapshot) {
                  return Padding(
                    padding: const EdgeInsets.symmetric(vertical: 24.0),
                    child: Text(snapshot.hasData
                        ? '${String.fromCharCodes(snapshot.data)}'
                        : ''),
                  );
                },
              )
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: _sendMessage,
          tooltip: 'Send message',
          child: Icon(Icons.send),
        ), // This trailing comma makes auto-formatting nicer for build methods.
      );
    }
  
    void _sendMessage() {
      if (_controller.text.isNotEmpty) {
        widget.channel.write(_controller.text);
      }
    }
  
    @override
    void dispose() {
      widget.channel.close();
      super.dispose();
    }
  }
  </code></pre>
  <hr />
  <p>When I run the code on the emulator, I get this error:
  &quot;
  Debug service listening on ws://127.0.0.1:59871/2EzZsU03nwc=/ws
  Syncing files to device AOSP on IA Emulator...&quot;</p>
  <p>AND</p>
  <p>&quot;E/flutter (24126): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: SocketException: OS Error: Connection timed out, errno = 110, address = 192.168.1.131, port = 51170&quot;</p>
  <p>How can i solve this?</p>
  <p>Thanks.</p>