npm i --save nativescript-ip-protocol
- 版本:0.2.2
- GitHub: https://github.com/FloripaBit/nativescript-ip-protocol
- NPM: https://npmjs.net.cn/package/nativescript-ip-protocol
- 下载量
- 昨天:0
- 上周:0
- 上个月:0
nativescript-ip-protocol
此插件旨在在原生平台(iOS 和 Android)上使用简单的 IP 协议。
目前仅支持 UDP 消息。
安装
tns plugin add nativescript-ip-protocol
用法
您可以在存储库中查看 demo-angular,但基本用法如下所示
import { UdpProtocol } from 'nativescript-ip-protocol';
public startReceiving() {
const udpSocket: UdpProtocol = new UdpProtocol();
udpSocket.receiveWithTimeout(this.port, this.timeout)
.subscribe((msg) => {
this.receivedMessage = msg;
}, (error) => {
console.error(error);
});
}
public receiveOnce() {
const udpSocket: UdpProtocol = new UdpProtocol();
udpSocket.receiveOnce(Number(this.port))
.subscribe((msg) => {
this.receivedMessage = msg;
}, (error) => {
console.error(error);
});
}
public sendBroadcast() {
const udpSocket: UdpProtocol = new UdpProtocol();
this.message = msgDefault + this.messageCount;
udpSocket.sendBroadcast(this.port, this.message)
.subscribe(() => {
this.status = "Broadcast message sent";
this.messageCount++;
});
}
public sendUnicast() {
const udpSocket: UdpProtocol = new UdpProtocol();
this.message = msgDefault + this.messageCount;
udpSocket.sendUnicast(this.ip, this.port, this.message)
.subscribe(() => {
this.status = "Unicast message sent";
this.messageCount++;
});
}
许可证
MIT
感谢
特别感谢 NathanaelA,他帮助解决了悬而未决的问题