Receiving data on the web server
In the previous recipe, we made a client app that sends its data to a web server in JSON format. In this recipe, we will make the web server that receives this data step by step, possibly process it, and then send it back to the client. You can find the code in the script server\webserver.dart
in the project post_form
.
How to do it...
Perform the following steps to make this work:
- The following is the code that starts the web server:
import 'dart:io'; const HOST = '127.0.0.1'; const PORT = 4040; void main() { HttpServer.bind(HOST, PORT).then(acceptRequests, onError: handleError); }
- The
acceptRequests
function describes how the web server handles incoming requests based on their method as follows:void acceptRequests(server) ...
Get Dart: Scalable Application Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.