I wanna create a localhost server in mobile phone so that it can serve a react app. Actually I have to run VML in flutter and since there is no any option to run the VML in server I'm trying to create react application, run VML there and then show it on webview in flutter application.
I tired use shelf package of flutter to create a localhost that can serve react application but it throws errors:
ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: SocketException: Failed to create server
socket (OS Error: The shared flag to bind() needs to be true if binding multiple times on the same (address, port) combination.),
address = localhost, port = 8080
My Code is:
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_static/shelf_static.dart';
class StaticServer {
void createServer() {
var handler = createStaticHandler('/storage/emulated/0/build',
defaultDocument: 'index.html');
io.serve(handler, 'localhost', 8080);
}
}
My Logs Are:
PS D:\Programming\webserver> flutter run -d "Infinix X655C" --web-port=8080 --web-hostname=127.0.0.1
Launching lib\main.dart on Infinix X655C in debug mode...
Running Gradle task 'assembleDebug'... 14.7s
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app-debug.apk... 11.3s
Syncing files to device Infinix X655C... 145ms
Flutter run key commands.
r Hot reload.
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
A Dart VM Service on Infinix X655C is available at: http://127.0.0.1:56219/hx50aWU-HCw=/
I/WebViewFactory( 5880): Loading com.google.android.webview version 109.0.5414.117 (code 541411733)
W/linker ( 5880): Warning: "/data/app/com.google.android.webview-iMATZcTFgqR3lefayVYL0g==/base.apk!/lib/arm64-v8a/libmonochrome.so"
unused DT entry: unknown processor-specific (type 0x70000001 arg 0x0) (ignoring)
W/ample.webserve( 5880): Accessing hidden method Landroid/os/Trace;->isTagEnabled(J)Z (greylist, reflection, allowed)
W/ample.webserve( 5880): Accessing hidden method Landroid/os/Trace;->traceBegin(JLjava/lang/String;)V (greylist, reflection, allowed
)
W/ample.webserve( 5880): Accessing hidden method Landroid/os/Trace;->traceEnd(J)V (greylist, reflection, allowed)
W/ample.webserve( 5880): Accessing hidden method Landroid/os/Trace;->asyncTraceBegin(JLjava/lang/String;I)V (greylist, reflection, a
llowed)
W/ample.webserve( 5880): Accessing hidden method Landroid/os/Trace;->asyncTraceEnd(JLjava/lang/String;I)V (greylist, reflection, all
owed)
I/cr_WVCFactoryProvider( 5880): Loaded version=109.0.5414.117 minSdkVersion=29 isBundle=true multiprocess=true packageId=2
I/cr_LibraryLoader( 5880): Successfully loaded native library
I/cr_CachingUmaRecorder( 5880): Flushed 8 samples from 8 histograms.
I/flutter ( 5880): Checking the permission for the first time
W/chromium( 5880): [WARNING:dns_config_service_android.cc(115)] Failed to read DnsConfig.
I/Choreographer( 5880): Skipped 32 frames! The application may be doing too much work on its main thread.
D/ActivityThread( 5880): topPackage=com.example.webserver;topClass=.MainActivity;curtPackagecom.example.webserver
W/ample.webserve( 5880): Accessing hidden method Landroid/media/AudioManager;->getOutputLatency(I)I (greylist, reflection, allowed)
W/cr_media( 5880): registerBluetoothIntentsIfNeeded: Requires BLUETOOTH permission
W/IMGSRV ( 5880): glGetString:4370: Override GL_RENDERER PowerVR SGX Doma
I/chatty ( 5880): uid=10377(com.example.webserver) Chrome_InProcGp identical 3 lines
W/IMGSRV ( 5880): glGetString:4370: Override GL_RENDERER PowerVR SGX Doma
D/NetworkSecurityConfig( 5880): No Network Security Config specified, using platform default
W/IMGSRV ( 5880): glGetString:4370: Override GL_RENDERER PowerVR SGX Doma
I/chatty ( 5880): uid=10377(com.example.webserver) Chrome_InProcGp identical 2 lines
W/IMGSRV ( 5880): glGetString:4370: Override GL_RENDERER PowerVR SGX Doma
D/ViewRootImpl[Toast]( 5880): hardware acceleration = true , fakeHwAccelerated = false, sRendererDisabled = false, forceHwAccelerate
d = false, sSystemRendererDisabled = false
W/IMGSRV ( 5880): glGetString:4370: Override GL_RENDERER PowerVR SGX Doma
I/chatty ( 5880): uid=10377(com.example.webserver) Chrome_InProcGp identical 2 lines
W/IMGSRV ( 5880): glGetString:4370: Override GL_RENDERER PowerVR SGX Doma
E/GraphicExt( 5880): GraphicExtModuleLoader::CreateGraphicExtInstance false
D/Surface ( 5880): Surface::connect(this=0x7a0a4b3000,api=1)
D/Surface ( 5880): Surface::setBufferCount(this=0x7a0a4b3000,bufferCount=3)
D/Surface ( 5880): Surface::allocateBuffers(this=0x7a0a4b3000)
W/IMGSRV ( 5880): glGetString:4370: Override GL_RENDERER PowerVR SGX Doma
W/IMGSRV ( 5880): glGetString:4370: Override GL_RENDERER PowerVR SGX Doma
The Flutter DevTools debugger and profiler on Infinix X655C is available at:
http://127.0.0.1:9100?uri=http://127.0.0.1:56219/hx50aWU-HCw=/
D/Surface ( 5880): Surface::disconnect(this=0x7a0a4b3000,api=1)
E/flutter ( 5880): **[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: SocketException: Failed to create server
socket (OS Error: The shared flag to bind() needs to be `true` if binding multiple times on the same (address, port) combination.),
address = localhost, port = 8080**
E/flutter ( 5880): #0 _NativeSocket.bind (dart:io-patch/socket_patch.dart:1032:7)
E/flutter ( 5880): <asynchronous suspension>
E/flutter ( 5880): #1 _RawServerSocket.bind.<anonymous closure> (dart:io-patch/socket_patch.dart:1812:15)
E/flutter ( 5880): <asynchronous suspension>
E/flutter ( 5880): #2 _ServerSocket.bind.<anonymous closure> (dart:io-patch/socket_patch.dart:2097:15)
E/flutter ( 5880): #3 _HttpServer.bind.<anonymous closure> (dart:_http/http_impl.dart:3186:27)
E/flutter ( 5880): <asynchronous suspension>
E/flutter ( 5880): #4 serve (package:shelf/shelf_io.dart:60:16)
E/flutter ( 5880): <asynchronous suspension>
E/flutter ( 5880):
Application finished.