0

As we all know Flutter is great for the front end, as I got into working with flutter I liked the Dart programming language very much I used it on some backend servers as well, Now it got me thinking if I can do this..

I have a aqueduct server (Aqueduct is a dart package, which is very similar to express on node.js)

import 'dart:async';
import 'dart:io';
import 'package:aqueduct/aqueduct.dart';
import 'package:aqueduct/managed_auth.dart';

Future main() async {
  final app = Application<App>()
    ..options.configurationFilePath = 'config.yaml'
    ..options.port = 8888;

  await app.start(numberOfInstances: 3);
}

class App extends ApplicationChannel {
//server side logic
}

will the server/app be successfully built if I make the above main() as the entry point of the flutter app, successfully making the flutter app running on the android device to act as a server?

Or

how can I make it work if the above code fails?

PS: I have not tried this yet. for your information: a node.js express server can be (may be) run on android using Node.js ARM

5
  • yes http package can be used to communicate with the server, here I'm asking about making the Flutter app as a server running on the android VM in the cloud Commented Jun 13, 2020 at 8:10
  • no express exists for dart, i use aqueduct on my small dart backend, okay for easier approach ill consider aqueduct in the question Commented Jun 13, 2020 at 8:21
  • I've updated the question, I exactly know how a server works, you know we can run node.js server on Android OS right? In the same way I'm asking is there a way to run the dart aqueduct server on the android OS Commented Jun 13, 2020 at 8:58
  • Sorry.. never heard of it but by googling it I can see that you can do it... I still don't understand why would anyone want to put server on android device or what would be the purpose of it.. Well good luck with your question then Commented Jun 13, 2020 at 9:07
  • May be OS limitation !! ;) Commented Jun 13, 2020 at 9:19

2 Answers 2

5

The below code runs a server on the port 4040 inside a flutter app

import 'dart:io';

Future main() async {
  // #docregion bind
  var server = await HttpServer.bind(
    InternetAddress.loopbackIPv4,
    4040,
  );
  // #enddocregion bind
  print('Listening on localhost:${server.port}');

  // #docregion listen
  await for (HttpRequest request in server) {
    request.response.write('Hello, world!');
    await request.response.close();
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0

if all your liberies is exiting on the flutter phone compiler your server will run without problem probably but if it is not you can looking for anther libery or try to download the libery source code and put it with your dart files

NOTE : I wanna know why you hadn't try to do an small experiment to see if it's work before posting this qustion

3 Comments

My laptop was not with me at the time, let me try it now
If it is work a love to see your source code I may need I similar thing in I game app I am planning to build
I guess for that webRTC is the best bet

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.