Created
February 13, 2016 15:24
-
-
Save gjz010/48faaed64bb1bc21865f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var net=require('net'); | |
var HOST='127.0.0.1'; | |
var PORT=18089; | |
var WEBSOCKET_ADDR='https://spigotwsbridge-gjz010no1.rhcloud.com/'; | |
var localserver=net.createServer(function(sock){ | |
console.log('CONNECTED: ' + | |
sock.remoteAddress + ':' + sock.remotePort); | |
var ws=require('socket.io-client')(WEBSOCKET_ADDR); | |
ws.on('connect', function(){}); | |
ws.on('pipeddata', function(data){sock.write(data)}); | |
ws.on('disconnect', function(){}); | |
sock.on('data', function(data) { | |
//console.log('DATA ' + sock.remoteAddress + ': ' + data); | |
// 回发该数据,客户端将收到来自服务端的数据 | |
//sock.write('You said "' + data + '"'); | |
ws.emit("pipeddata",data); | |
}); | |
// 为这个socket实例添加一个"close"事件处理函数 | |
sock.on('close', function(data) { | |
console.log('CLOSED: ' + | |
sock.remoteAddress + ' ' + sock.remotePort); | |
}); | |
sock.on('error',function(err){ | |
}); | |
}).listen(PORT,HOST); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment