简体   繁体   English

Dart Nodejs和Socketio

[英]Dart Nodejs and Socketio

What are my options for converting a socketio nodejs application to dart? 将socketio nodejs应用程序转换为dart有哪些选择? Is there support for nodejs servers using dart somehow (ideally with all the fancy debugging capabilities of the dart editor)? 是否支持使用dart的nodejs服务器(理想情况下使用dart编辑器的所有奇特的调试功能)? Does socketio have a dart based library? socketio有基于飞镖的图书馆吗?

Dart has a server side VM, just like V8 has a server side VM in the form of node.js. Dart有一个服务器端虚拟机,就像V8有一个node.js形式的服务器端虚拟机一样。

Take a look at Adam Smith's webserver chat sample , which uses websockets on the server side to communicate with websockets on the client side, with both parts being written in Dart. 看看Adam Smith的网络服务器聊天示例 ,它使用服务器端的websockets与客户端的websockets进行通信,两个部分都是用Dart编写的。

The key parts for the server side look like: 服务器端的关键部分如下:

import "dart:io";

main() {
  HttpServer server = new HttpServer();

  WebSocketHandler wsHandler = new WebSocketHandler();
  server.addRequestHandler((req) => req.path == "/ws", wsHandler.onRequest);

  wsHandler.onOpen = (WebSocketConnection conn) {
     conn.onMessage = (message) {
       print(message);
       conn.send("hello, this is the server");
     };
  };

  server.listen("127.0.0.1",8080);
}

Then on the client, something like 然后在客户端,像

import "dart:html"; 
main() {
  var ws = new WebSocket("ws://127.0.0.1:8080/ws");
  ws.on.open.add( (a) {
    ws.send("hello, this is the client");
  });
  ws.on.message.add( (messsage) {
    print(message);
  });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM