Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to create server socket when run flutter web application

Im working on a flutter project. Its run perfectly on android emulator but when I want to run as web application I face to this problem:

Launching lib\main.dart on Chrome in debug mode...
Finished with error: Failed to bind web development server:
SocketException: Failed to create server socket (OS Error: Failed to start accept), address = 
localhost, port = 5403

I have tried to run an other simple project but I faced same error. I did every step according to flutter official documentation. This is my flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v1.17.0, on Microsoft Windows [Version 10.0.18363.778], locale en-US)

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.0-rc2)
[√] Chrome - develop for the web
[√] Android Studio (version 3.6)
[√] IntelliJ IDEA Ultimate Edition (version 2019.3)
[√] VS Code (version 1.44.2)
[√] Connected device (3 available)

• No issues found!

I have searched the internet but there is not any good solution for this problem .

Could you please help me?

Thanks in advance.

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
  theme: ThemeData(
    primarySwatch: Colors.blue,
    visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
  _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
          'You have pushed the button this many times:',
        ),
        Text(
          '$_counter',
          style: Theme.of(context).textTheme.headline4,
        ),
      ],
    ),
  ),
  floatingActionButton: FloatingActionButton(
    onPressed: _incrementCounter,
        tooltip: 'Increment',
    child: Icon(Icons.add)
      ),
    );
  }
}

I run flutter -v -d chrome run in command windows as administrator and this is the response:

[  +32 ms] executing: [C:\android\flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[ +129 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[   +2 ms] d3ed9ec945f8869f0e136c357d0c2a6be2b60c98
[        ] executing: [C:\android\flutter/] git describe --match *.*.* --first-parent --long --tags
[ +123 ms] Exit code 0 from: git describe --match *.*.* --first-parent --long --tags
[        ] 1.17.0-dev.3.1-0-gd3ed9ec94
[  +16 ms] executing: [C:\android\flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[  +96 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/beta
[        ] executing: [C:\android\flutter/] git ls-remote --get-url origin
[  +87 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[ +254 ms] executing: [C:\android\flutter/] git rev-parse --abbrev-ref HEAD
[  +97 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[   +2 ms] beta
[  +58 ms] Artifact Instance of 'AndroidMavenArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[   +2 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +7 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[   +2 ms] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[   +2 ms] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +30 ms] executing: C:\android\sdk\platform-tools\adb.exe devices -l
[  +90 ms] List of devices attached
           emulator-5554          device product:sdk_google_phone_x86 model:Android_SDK_built_for_x86 device:generic_x86
           transport_id:2
[  +20 ms] Artifact Instance of 'AndroidMavenArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[   +2 ms] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[   +8 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[   +2 ms] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[   +2 ms] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[ +348 ms] Generating C:\AndroidStudioProjects\Samsung
mobile\flutter_app\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java
[ +170 ms] Launching lib\main.dart on Chrome in debug mode...
[  +73 ms] "flutter run" took 948ms.
Failed to bind web development server:
SocketException: Failed to create server socket (OS Error: Failed to start accept), address = localhost, port = 13632

#0      throwToolExit (package:flutter_tools/src/base/common.dart:14:3)
#1      WebAssetServer.start (package:flutter_tools/src/build_runner/devfs_web.dart:221:7)
<asynchronous suspension>
#2      WebDevFS.create (package:flutter_tools/src/build_runner/devfs_web.dart:605:43)
#3      _ResidentWebRunner.run.<anonymous closure>
(package:flutter_tools/src/build_runner/resident_web_runner.dart:426:44)
<asynchronous suspension>
#4      _ResidentWebRunner.run.<anonymous closure> (package:flutter_tools/src/build_runner/resident_web_runner.dart)
#5      asyncGuard.<anonymous closure> (package:flutter_tools/src/base/async_guard.dart:111:32)
#6      _rootRun (dart:async/zone.dart:1184:13)
#7      _CustomZone.run (dart:async/zone.dart:1077:19)
#8      _runZoned (dart:async/zone.dart:1619:10)
#9      runZonedGuarded (dart:async/zone.dart:1608:12)
#10     runZoned (dart:async/zone.dart:1536:12)
#11     asyncGuard (package:flutter_tools/src/base/async_guard.dart:109:3)
#12     _ResidentWebRunner.run (package:flutter_tools/src/build_runner/resident_web_runner.dart:407:20)
<asynchronous suspension>
#13     RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:564:37)
<asynchronous suspension>
#14     FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:722:18)
#15     _rootRunUnary (dart:async/zone.dart:1192:38)
#16     _CustomZone.runUnary (dart:async/zone.dart:1085:19)
#17     _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
#18     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
#19     Future._propagateToListeners (dart:async/future_impl.dart:711:32)
#20     Future._completeWithValue (dart:async/future_impl.dart:526:5)
#21     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:36:15)
#22     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:298:13)
#23     RunCommand.usageValues (package:flutter_tools/src/commands/run.dart)
#24     _rootRunUnary (dart:async/zone.dart:1192:38)
#25     _CustomZone.runUnary (dart:async/zone.dart:1085:19)
#26     _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
#27     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
#28     Future._propagateToListeners (dart:async/future_impl.dart:711:32)
#29     Future._completeWithValue (dart:async/future_impl.dart:526:5)
#30     Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:556:7)
#31     _rootRun (dart:async/zone.dart:1184:13)
#32     _CustomZone.run (dart:async/zone.dart:1077:19)
#33     _CustomZone.runGuarded (dart:async/zone.dart:979:7)
#34     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1019:23)
#35     _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#36     _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
#37     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#38     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:169:5)

like image 499
Tabrizapps Avatar asked Apr 19 '20 04:04

Tabrizapps


2 Answers

I solved this problem. In my case I need to determine the port

flutter run -d chrome --web-port=8080 --web-hostname=127.0.0.1

use this code in terminal.

like image 52
Tabrizapps Avatar answered Sep 20 '22 13:09

Tabrizapps


For people using VS Code. You can add these arguments to lunch.json file. This way, you can simply press F5 and debug your app. This file should be in .vscode folder. If it isn't there, create it. It should look like this.

{
  "version": "0.2.0",
  "configurations": [
    {
        "name": "Flutter",
        "request": "launch",
        "type": "dart",
        "args": [
            "--web-hostname",
            "127.0.0.1"
        ]
    }
  ]
}
like image 31
onex941 Avatar answered Sep 20 '22 13:09

onex941