IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Dart Discussion :

Unhandled Exception: SocketException: Connection timed out


Sujet :

Dart

  1. #1
    Membre du Club
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Janvier 2018
    Messages
    300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Assistant aux utilisateurs
    Secteur : Distribution

    Informations forums :
    Inscription : Janvier 2018
    Messages : 300
    Points : 67
    Points
    67
    Par défaut Unhandled Exception: SocketException: Connection timed out
    Bonjour,

    J'apprends le DART, et j'utilise le connector MySQL "mysql1".
    J'ai l'erreur suivante :
    E/flutter (32240): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: SocketException: Connection timed out, host: localhost, port: 3306
    E/flutter (32240): #0 _NativeSocket.connect.<anonymous closure>.<anonymous closure> (dart:io-patch/socket_patch.dart:988:11)
    E/flutter (32240): #1 _RootZone.run (dart:async/zone.dart:1655:54)
    main.dart :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    import 'package:flutter/material.dart';
    import 'connectionDatabase.dart';
     
    void main() {
      runApp(const MyApp());
    }
     
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
     
      // This widget is the root of your application.
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          debugShowCheckedModeBanner: false,
          theme: ThemeData(
            // This is the theme of your application.
            //
            // Try running your application with "flutter run". You'll see the
            // application has a blue toolbar. Then, without quitting the app, try
            // changing the primarySwatch below to Colors.green and then invoke
            // "hot reload" (press "r" in the console where you ran "flutter run",
            // or simply save your changes to "hot reload" in a Flutter IDE).
            // Notice that the counter didn't reset back to zero; the application
            // is not restarted.
            primarySwatch: Colors.blue,
          ),
          home: const MyHomePage(title: 'Page d\'accueil'),
        );
      }
    }
     
    class MyHomePage extends StatefulWidget {
      const MyHomePage({super.key, required this.title});
      final String title;
     
      @override
      State<MyHomePage> createState() => _MyHomePageState();
    }
     
    class _MyHomePageState extends State<MyHomePage> {
     
      var db = ConnectionDatabase();
      var name = '';
     
      void _getCustomer(){
        print('_getCustomer');
        db.getConnection().then((conn) {
          String sql = 'SELECT name FROM users WHERE id=1;';
          print('_getCustomer2');
          conn.query(sql).then((results){
            for(var row in results) {
              setState(() {
                name = row[0];
                print('The value of the input is: $name');
              });
            }
          });
          conn.close();
        });
      }
     
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text(widget.title),
          ),
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                const Text(
                  'Name :',
                ),
                Text(
                  name,
                  style: Theme.of(context).textTheme.headlineMedium,
                ),
              ],
            ),
          ),
          floatingActionButton: FloatingActionButton(
            onPressed: _getCustomer,
            tooltip: 'Increment',
            child: const Icon(Icons.add),
          ), // This trailing comma makes auto-formatting nicer for build methods.
        );
      }
    }
    connectionDatabase.dart :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    import 'dart:async';
    import 'package:mysql1/mysql1.dart';
     
    class ConnectionDatabase {
      static String host = 'localhost',
                    user = 'chopetondiplome',
                    password = "chopetondiplome",
                    db = 'chopetondiplome';
      static int port = 3306;
     
      ConnectionDatabase();
     
      Future<MySqlConnection> getConnection() async {
        var settings = ConnectionSettings(
          host: host,
          port: port,
          user: user,
          password: password,
          db: db
        );
        print(host);
        return await MySqlConnection.connect(settings);
      }
    }
    Une idée du problème ? merci

  2. #2
    Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2015
    Messages
    76
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Janvier 2015
    Messages : 76
    Points : 58
    Points
    58
    Par défaut
    Je me baserais surtout sur le fait que Flutter te signal une connection timeout.
    Ce qui pourrait signifier qu'il n'arrive tout simplement pas à se connecter déjà.

    Es-tu sûr d'avoir validé cette connexion déjà ? Pour savoir si c'est dût à ta requête ou aux données ou ton paramétrage de base de données

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [FOP] PB connection timed out
    Par benoît82 dans le forum XSL/XSLT/XPATH
    Réponses: 2
    Dernier message: 01/12/2008, 11h53
  2. Eclipse JBOSS 10060 Connection timed out
    Par g25452 dans le forum Eclipse Java
    Réponses: 0
    Dernier message: 31/07/2008, 14h23
  3. TestNG : Connection timed out
    Par onclezeb dans le forum Seam
    Réponses: 1
    Dernier message: 13/06/2008, 11h24
  4. Tâche cron et Connection timed out in headers ?
    Par sam_owm dans le forum Apache
    Réponses: 1
    Dernier message: 24/04/2008, 10h00
  5. [IdWhois] Connect Timed Out
    Par xenos dans le forum Delphi
    Réponses: 7
    Dernier message: 06/06/2006, 11h05

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo