2016-07-06 11 views
0
//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(); 

、出力EADDRNOTAVAILにnodejs HTTPリクエストすぐ

{[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' } 

2回目 (実際に私は私たちのDHCP-ステートレスが壊れているので、アドレスをテストしてい)

{ [Error: connect ETIMEDOUT 2404:6800:4005:805::200e:80] 
code: 'ETIMEDOUT', 
errno: 'ETIMEDOUT', 
syscall: 'connect', 
address: '2404:6800:4005:805::200e', 
port: 80 } 
を新しいアドレス結果を追加した後

私は2回目の出力から描画できます。

new-netipaddressに追加しましたコールバックがうまく動作しますので、彼は(私たちがすることを設計し、タイムアウト、が)、適切に

に対処しますが、それは最初の実行に失敗した理由を1回目にコールバックがとてもEADDRNOTAVAIL

で失敗しましたか?それを避ける方法は?仮アドレスの@SanderSteffannの知識に

+0

非常に良いではないかもしれないあなたが作ったときのアドレスは、暫定的な状態のままにしました要求。 Duplicate Address Detectionが完了し、アドレスが使用可能になるまで少し時間がかかるかもしれません。 –

+0

@SanderSteffann私はあなたが正しいと思いますが、それは私がチェックするのが速すぎます。私はexec( 'powershell get-netipaddress')をコールバックでは、仮の代わりにaddressStateが優先されます......しかし、アドレスを追加した直後は使用できないと思います。だから、私はそれを避けるために何をすべきですか? – wyj

+1

@SanderSteffannは劇的に解決策を見つけました。 execSync( 'powershell get-netipaddress')の後にリクエストを呼び出すと、addressStateが優先され、リクエストが機能します。 – wyj

答えて

1

おかげで、私は解決策を考えるが、

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(); 

line 2:++++execSync('powershell get-netipaddress '+ip)

関連する問題