Sockets 未来如何合并渡槽<;请求者响应>;使用dart控制台应用程序?
感谢来自虚空王国的布莱恩。我在过去的两天(以及几周的研究)中苦苦挣扎,现在我可以使用dart tcp套接字从旧系统中快速获取大数据。使用dart控制台应用程序的过程比dart未来项目快得多 现在的问题是如何将dart控制台应用程序与未来的渡槽应用程序混合。在下文中,我将我的问题放在(*******)之后 如果我使用Socket.connect(“192…”在Future内部,该过程将非常缓慢,有时会返回空响应。因此,我的问题是如何将aqueduct Future与dart控制台应用程序合并 渡槽.io部分Sockets 未来如何合并渡槽<;请求者响应>;使用dart控制台应用程序?,sockets,merge,dart,console-application,aqueduct,Sockets,Merge,Dart,Console Application,Aqueduct,感谢来自虚空王国的布莱恩。我在过去的两天(以及几周的研究)中苦苦挣扎,现在我可以使用dart tcp套接字从旧系统中快速获取大数据。使用dart控制台应用程序的过程比dart未来项目快得多 现在的问题是如何将dart控制台应用程序与未来的渡槽应用程序混合。在下文中,我将我的问题放在(*******)之后 如果我使用Socket.connect(“192…”在Future内部,该过程将非常缓慢,有时会返回空响应。因此,我的问题是如何将aqueduct Future与dart控制台应用程序合并 渡槽
class NtmsApiController extends Controller {
@override
Future<RequestOrResponse> handle(Request request) async {
try {
if (request.path.remainingPath != null) {
_requestValue = request.path.remainingPath;
// (********) In here I need to add below code, how?
}
} else {
_secureResponse = "$_errorData";
}
} catch (e) {
_secureResponse = "$_errorData";
}
return new Response.ok("$_secureResponse")
..contentType = ContentType.json;
}
}
import 'dart:io';
import 'dart:async';
Socket socket;
String _response;
String _requestedData;
Stopwatch _stopWatch;
void main() {
_stopWatch = Stopwatch()..start();
_response = "";
_requestedData = "Q77:_:NBRT:_:6785417534\r\n";
Socket.connect("192.168.22.120", 3000).then((Socket sock) {
socket = sock;
socket.write('$_requestedData\r\n');
socket.listen(dataHandler,
onError: errorHandler,
onDone: doneHandler,
cancelOnError: false);
}).catchError((AsyncError e) {
print("Unable to connect: $e");
});
print("_requestedData: $_requestedData");
}
void dataHandler(data){
_response = new String.fromCharCodes(data).trim();
_printResponse(_response);
}
void errorHandler(error, StackTrace trace){
print(error);
}
void doneHandler(){
socket.destroy();
}
void _printResponse(String _response) {
// approximately I get 500 rows with 20 column data in 250ms
print("$_response ... (${_stopWatch.elapsedMilliseconds} ms)");
_stopWatch..stop();
if(_stopWatch.isRunning == false) {
socket.close();
// (********)return response object to aqueduct Future request_response--- how?
}
}