chrome net
1.0.0
net API此模塊可讓您在Chrome打包應用程序中使用Node.js Net(TCP)API。
與其學習Chrome chrome.sockets的怪癖。 socketsAPI用於Chrome應用程序中的網絡,只需使用您熟悉的高級節點API即可。然後,使用瀏覽器編譯代碼,您都設置了!
npm install chrome-net
使用節點的net API,包括所有參數列表速記和變體。
示例TCP客戶端:
var net = require ( 'chrome-net' )
var client = net . createConnection ( {
port : 1337 ,
host : '127.0.0.1'
} )
client . write ( 'beep' )
client . on ( 'data' , function ( data ) {
console . log ( data )
} )
// .pipe() streaming API works too!示例TCP服務器:
var net = require ( 'chrome-net' )
var server = net . createServer ( )
server . on ( 'listening' , function ( ) {
console . log ( 'listening' )
} )
server . on ( 'connection' , function ( sock ) {
console . log ( 'Connection from ' + sock . remoteAddress + ':' + sock . remotePort )
sock . on ( 'data' , function ( data ) {
console . log ( data )
} )
} )
server . listen ( 1337 )有關完整的API文檔,請參見Nodejs.org:NET
要運行測試,請使用npm test 。測試將運行TCP和UDP服務器,並使用瀏覽客戶端代碼啟動一些不同的Chrome打包應用程序。這些測試目前需要在Windows或Mac上的Chrome Canary上進行Chrome。如果您在Linux上,請隨時發送拉動請求以解決此限制。
麻省理工學院。版權(C)Feross Aboukhadijeh,John Hiesey和Janschär。