在EADDRNOTAVAIL中添加新地址结果后立即发出nodejs http请求

时间:2016-07-06 12:39:04

标签: node.js windows powershell ipv6

//nodejs code

var ip=<some_ip_address>;
//for me it is 2001:250:401:3611:50c6:6b18:e8f7:f882

exec('powershell new-netipaddress '+ip+' -InterfaceAlias WLAN',(e,so,se)=>{
    http.request({
        host:'2404:6800:4005:805::200e',//just use google as an example
        family:6,
        localAddress:ip
    },(res)=>{
        console.log('reachable');
    }).on('error',(e)=>{
        console.log(e);
    })
}).stdin.end();

然后输出

{[Error: bind EADDRNOTAVAIL 2001:250:401:3611:50c6:6b18:e8f7:f882]
code: 'EADDRNOTAVAIL',
errno: 'EADDRNOTAVAIL',
syscall: 'bind',
address: '2001:250:401:3611:50c6:6b18:e8f7:f882' }

第二次 (实际上我正在测试地址,因为我们的DHCP无状态是坏的)

{ [Error: connect ETIMEDOUT 2404:6800:4005:805::200e:80]
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: '2404:6800:4005:805::200e',
port: 80 }

我可以从第二次输出中抽取,

new-netipaddress确实正确地添加了地址,因此回调运行良好(虽然超时,我们设计了它)

但第一次使用EADDRNOTAVAIL

时回调失败

那为什么第一次运行会失败呢?以及如何避免它?

1 个答案:

答案 0 :(得分:1)

感谢@SanderSteffann对暂定地址的了解,我想到了一个解决方案,但可能不是很好

with
     test_data (date1, date2) as (
       select sysdate - 3605 / 86400, sysdate from dual
     )
select to_char(trunc(date2 - date1)) || ' days and ' || 
            to_char(date '1970-01-01' + (date2 - date1), 'hh24:mi:ss')
from   test_data;



TO_CHAR(TRUNC(DATE2-DATE1))||'DAYSAND'||TO_CHAR(DATE'1970-
----------------------------------------------------------
0 days and 01:00:05

<强> exec('powershell new-netipaddress '+ip+' -InterfaceAlias WLAN',(e,so,se)=>{ http.request({ host:'2404:6800:4005:805::200e',//just use google as an example family:6, localAddress:ip },(res)=>{ console.log('reachable'); }).on('error',(e)=>{ console.log(e); }) }).stdin.end(); exec('powershell new-netipaddress '+ip+' -InterfaceAlias WLAN',(e,so,se)=>{ execSync('powershell get-netipaddress '+ip) http.request({ host:'2404:6800:4005:805::200e',//just use google as an example family:6, localAddress:ip },(res)=>{ console.log('reachable'); }).on('error',(e)=>{ console.log(e); }) }).stdin.end();