[英]Node.JS proxy for FAST protocol
我正在嘗試通過 UDP 多播(PPTP 連接)為 FAST 協議創建 Node.JS 代理。
const os = require('os');
const osInterfaceName = 'VPN-подключение';
const endpoints = {
'FUT-TRADES': {
A: {ip: '239.195.9.9', port: 42009},
B: {ip: '239.195.137.9', port: 43009},
},
'OPT-TRADES': {
A: {ip: '239.195.9.25', port: 42025},
B: {ip: '239.195.137.25', port: 43025},
}
};
const dgram = require('dgram');
const osInterface = os.networkInterfaces()[osInterfaceName] !== undefined ? os.networkInterfaces()[osInterfaceName][0] : { address: '0.0.0.0' };
const clients = {};
for (let key in endpoints) {
for (let serverId in endpoints[key]) {
const client = dgram.createSocket('udp4');
client.on('listening', function () {
const address = client.address();
console.log(`UDP Client listening on ${address.address}: ${address.port} [${serverId}]`);
client.setBroadcast(true)
client.setMulticastTTL(128);
client.addMembership(endpoints[key][serverId].ip, osInterface.address);
});
client.on('message', function (message, remote) {
console.log('Message from: ' + remote.address + ':' + remote.port +' - ' + message);
});
client.on('error', function (error) {
console.log(`UDP error: ${error.stack}`);
});
client.bind(endpoints[key][serverId].port, osInterface.address);
clients[`${key}:${serverId}`] = client;
}
}
如果我在本地測試它(啟動服務器並發送多播消息 - 它顯示在客戶端上),但我不能將它與 MOEX 流一起使用。 在日志中,除了“UDP 客戶端偵聽 1.1.5.171:42009 [A]...”(對於端點列表中的每個流)之外,什么都沒有。
但是根據netsh interface ip show joins客戶端已經成功加入多播組。
看起來我已經找到了問題的根源,替代解決方案也是如此。
僅僅加入組播組是不夠的,還需要開啟數據包的源過濾:
安裝並啟動 smcroute 守護進程:apt-get install smcroute smcroute -d
加入多播組並啟用過濾(需要源 IP) smcroute -j ppp0 91.203.253.235 239.195.9.9
然后應用程序開始獲取多播數據包:tcpdump -i ppp0 -s 65534 host 239.195.9.9
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.