当前位置: 首页 > 软件库 > 手机/移动开发 > >

nativescript-simple-networking

UDP and TCP sockets for NativeScript
授权协议 MIT License
开发语言 JavaScript TypeScript
所属分类 手机/移动开发
软件类型 开源软件
地区 不详
投 递 者 麹承
操作系统 iOS
开源组织
适用人群 未知
 软件概览

NativeScript Simple Networking

Basic UDP and TCP sockets for NativeScript.

Supported platforms

  • Android (any device with Android 4.4 and higher)

There is no support for iOS (yet), as I am not an iOS developer. Contributionsfor adding iOS support are welcome!

Installing

tns plugin add nativescript-simple-networking

Usage

This plugin provides three classes: UdpServer, TcpClient and TcpServer.All of them provide similar, callback-based, interface. An example of usage isworth a thousands words and therefore here is a TypeScript example:

import {UdpServer, TcpClient, TcpServer} from "nativescript-simple-networking";
import {Address4} from "ip-address";

var udpServer = new UdpServer();
udpServer.onPacket = (sender: Address4, message: string) => {
    console.log("Message from UDP: ", message);
};
udpServer.onError = (id: number, message: string) => {
    console.log("UDP error for action #", id, ": ", message);
};
udpServer.onFinished = (id: number) => {
    console.log("UDP finished action #", id);
};

// Start listening on port 33333
var udpConnectEvent: number = udpServer.start(33333);
console.log("UDP start event is: ", udpConnectEvent);
// Broadcast a message
var udpBroadcastEvent: number = udpServer.send("255.255.255.255", "I am alive!");
console.log("UDP broadcast event is: ", udpBroadcastEvent);

// Start a TCP server listening on port 44444 with maximum 2 clients
var tcpServer = new TcpServer(2);
tcpServer.onClient = (client: Address4) => {
    console.log("New TCP client: ", client.adddress)
    tcpServer.send(client, "Welcome!");
};
tcpServer.onData = (client: Address4, data: string) => {
    console.log("New data from client ", client.address, ": ", data);
};
tcpServer.onError = (id: number, client: Address4, message: string) => {
    if (client)
        console.log("TCP server client error", client.address, ": ", message);
    else
        console.log("TCP server error: ", message);
};
tcpServer.onFinished = (id: number) => {
        console.log("TCP server finished transaction #", id);
};

tcpServer.start(44444);

// Connect to the TCP server
var tcpClient = new TcpClient();
tcpClient.onData = (data: string) => {
    console.log("Data from TCP client: ", data);
};
tcpClient.onError = (id: number, message: string) => {
    console.log("TCP client error for action #", id, ": ", message);
};
tcpClient.onFinished = (id: number) => {
    console.log("TCP client finished action #: ", id);
};

// Connect client, action IDs are ommited in this example - see UdpServer
tcpClient.start("localhost", 44444);
tcpClient.send("I am also alive!");

// When we are finished
udpServer.stop();
tcpServer.stop();
tcpClient.stop();

Contributing

Any contributions are welcome, feel free to submit a pull request on GitHub. Iwould appreciate a PR, which would add support for iOS.

Future Plans

  • support iOS
  • implement a wrapper for future-based interface
 相关资料
  • To install Tengine, just follow these three steps: $ ./configure $ make # make install By default, it will be installed to /usr/local/nginx. You can use the '--prefix' option to specify the root dire

  • 插入 // 单条插入 User user=new User(); // 省略entity属性赋值... ... elasticsearchTemplate.save(user); // 批量插入 LinkedList<User> users= new LinkedList<User>(); // 省略entity属性赋值... ... elasticsearchTemplate.save(user

  • 描述 (Description) 无需使用填充和颜色即可创建简单菜单。 .simple类包含在菜单中以创建一个简单的菜单栏。 例子 (Example) 以下示例演示了在Foundation中使用简单样式 - <!DOCTYPE html> <html> <head> <title>Foundation Template</title> <meta name = "vi

  • 辅助 mpvue 快速开发 Page 级小程序页面的工具,所以也需要有一定的小程序开发经验。 mpvue QuickStart 只支持项目级应用开发,对 Page 级和自定义组件 Component 级小程序页面开发场景缺少支持,而 simple 刚好来填补这部分需求,用以支持 mpvue 和原生小程序(或者其他方式小程序)的混用。 工具用法 command line # install by g

  • simple-rpc 是一款基于 netty 的 RPC 框架,现有功能: 基本的客户端、服务端交互 提供代理实现接口 spring 集成, xml配置和Java Config配置方式 服务发布订阅 DONE 断线重连 DONE RoadMap 服务心跳检测 连接池 服务注册发布功能 服务管理、监控 服务调用日志链路跟踪 集成swagger功能,提供文档、测试、客户端生成 使用示例 // 服务接口

  • JOpt Simple 是一个简单的、测试驱动的命令行解析器,支持 POSIX getopt() 和 GNU getopt_long() 示例代码: package joptsimple.examples;import joptsimple.OptionParser;import joptsimple.OptionSet;import org.junit.Test;import static or