nodejs redis 文件 二进制存取

nodejs websocket 收发二进制数据

ws模块可以很方便的完成websocket的收发功能,npm上的说明如下:

ws is a simple to use WebSocket implementation, up-to-date against RFC-6455, and probably the fastest WebSocket library for node.js.

server端代码:

'use strict';

var WebSocketServer = require('ws').Server
var wss    = new WebSocketServer({ port: 5505 });

wss.on('connection', function connection(ws) {
   
  ws.on('message', function incoming(data, flags) {
   
    console.log('flags.binary: '+flags.binary+', flags.mask: '+flags.mask);
    console.log('data:'+ typeof data);
    console.log(data);
  });
});

client端代码;

'use strict';

var WebSocket = require('ws');
var ws = new WebSocket('ws://127.0.0.1:5505/');

ws.on('open', function open() {
   
  var array = new Uint8Array(4);
  array[0] = parseInt(Math.random()*0xFF);
  array[1] = parseInt(Math.random()*0xFF);
  array[2] = parseInt(<

你可能感兴趣的:(nodejs,redis,nodejs,二进制,文件)