옵션 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | var http = require('http'); var fs = require('fs'); var WebSocketServer= require('ws').Server; var WebSocketStream= require('websocket-stream'); var wss = new WebSocketServer({server:server}) var clientId = 0; wss.on('connection', function(ws){ var Id = ++clientId; console.log('#%d 클라이언트 연결. 프로세스 : %d',Id,process.pid); var stream = WebSocketStream(ws); fs.createReadStream('google.jpg').pipe(stream); : : : }); | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <script type='text/javascript'> $(document).ready(function(event){ var address= 'ws://192.168.123.227:50000' socket = new WebSocket(address); socket.binaryType ="arraybuffer"; socket.onopen = function(event) { } socket.onmessage =function(event) { var temp = new Uint8Array(event.data); cc=btoa(String.fromCharCode.apply(null,temp)); $('#img').attr('src',"data:image/png;base64,"+cc); } socket.onerror = function(event) { } socket.onclose = function(event) { } }); | cs |