How to create HTTP server app in flutter?

Viewed 6215

I am working in flutter,I have to create an flutter app which create http server, and server our local phone storage, I am unable to find any flutter plugin related to creating http server in flutter, here is sample app,which I found in Playstore, it provide http server

Screenshot of that app

and Here is How it shows the page in

enter image description here

how I can create this app in Flutter ?, suggest any plugin for that.

1 Answers

It's possible without any third-party packages. Dart's io package provides functionalities to work with file, socket, http and other I/O related things. You can start listening for HTTP requests on a specific address and port using HttpServer.bind. Here is a snippet I found (link):

startServer() async {
  var server = await HttpServer.bind(InternetAddress.loopbackIPv4, 8080);
  print("Server running on IP : " +
      server.address.toString() +
      " On Port : " +
      server.port.toString());
  await for (var request in server) {
    request.response
      ..headers.contentType =
          new ContentType("text", "plain", charset: "utf-8")
      ..write('Hello, world')
      ..close();
  }
}
Related