platform/archived_packages/wings/example/socket.dart

28 lines
766 B
Dart
Raw Normal View History

2019-04-29 08:22:36 +00:00
import 'dart:convert';
import 'dart:typed_data';
import 'package:angel_framework/angel_framework.dart';
2019-04-26 23:22:30 +00:00
import 'package:angel_wings/angel_wings.dart';
2021-06-20 12:37:20 +00:00
void main() async {
2019-04-29 08:22:36 +00:00
var app = Angel();
2019-04-26 23:22:30 +00:00
var socket = await WingsSocket.bind('127.0.0.1', 3000);
2019-04-29 08:22:36 +00:00
print('Listening at http://localhost:3000');
2019-04-29 05:55:02 +00:00
await for (var fd in socket) {
2019-04-29 08:22:36 +00:00
var response = '''
HTTP/1.1 200 Not Found\r
Date: Fri, 31 Dec 1999 23:59:59 GMT\r
server: wings-test\r\n\r
Nope, nothing's here!
\r\n\r
''';
var bytes = utf8.encode(response);
var data = Uint8List.fromList(bytes);
var rq = await WingsRequestContext.from(app, fd);
print('Yay: $rq');
print(rq.headers);
writeToNativeSocket(fd.fileDescriptor, data);
closeNativeSocketDescriptor(fd.fileDescriptor);
2019-04-29 05:55:02 +00:00
}
2019-04-26 23:22:30 +00:00
}