qws
Version:
An HTML5 Web Sockets Server Module
86 lines (63 loc) • 2.21 kB
text/coffeescript
fs = require 'fs'
http = require 'http'
zlib = require 'zlib'
qws = require './index'
b1 = new Buffer [0xaa, 0x56, 0x4a, 0xce, 0x4d, 0x51, 0xb2, 0x52, 0xca, 0xc9, 0x4f, 0x4c, 0xf1, 0x4b, 0x2c, 0xc9, 0x2c, 0x4b, 0x55, 0xd2, 0x51, 0x4a, 0xcb, 0xcc, 0x49, 0x05, 0x8a, 0xe9, 0x67, 0x24, 0xeb, 0xe7, 0x81, 0xc5, 0xf4, 0x0b, 0x12, 0x4b, 0x32, 0x94, 0x6a, 0x01]
b2 = new Buffer [0xaa, 0x26, 0x4e, 0x71, 0x72, 0x71, 0x71, 0x7e, 0xae, 0x52, 0x2d]
b1 = new Buffer [0xaa, 0x56, 0x4a, 0xce, 0x4d, 0x51, 0xb2, 0x52, 0xca, 0xc9, 0x4f, 0x4c, 0xf1, 0x4b, 0x2c, 0xc9, 0x2c, 0x4b, 0x55, 0xd2, 0x51, 0x4a, 0xcb, 0xcc, 0x49, 0x05, 0x8a, 0xe9, 0x67, 0x24, 0xeb, 0xe7, 0x81, 0xc5, 0xf4, 0x0b, 0x12, 0x4b, 0x32, 0x94, 0x6a, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff]
b2 = new Buffer [0xaa, 0x26, 0x4e, 0x71, 0x72, 0x71, 0x71, 0x7e, 0xae, 0x52, 0x2d, 0x00, 0x00, 0x00, 0xff, 0xff]
b3 = new Buffer [0x22, 0x52, 0x75, 0x56, 0x61, 0x69]
b4 = new Buffer [0x6a, 0x51, 0xa5, 0x52, 0x2d, 0x00, 0x00, 0x00, 0xff, 0xff]
# b3 = fs.readFileSync 'compressed.bin'
# console.log process.memoryUsage()
de = zlib.createInflateRaw(chunkSize :1048576)
de.on 'data', (data)->
console.log data.length, data.toString()
de.on 'end', ->
console.log 1, process.memoryUsage()
de.reset()
console.log 2, process.memoryUsage()
# de.on
de.on zlib.Z_OK, (ok) ->
console.log 'ok'
de.on zlib.Z_STREAM_END, (ok) ->
console.log 'ok'
# de.write b1
# de.write b2
de.write b1
de.write b2
de.write b3
de.write b4
# console.log 1
de.end()
file = '''
<html>
<body>
<script>
var ws = new WebSocket("ws://localhost:8081/ws");
ws.onopen = function(){
console.log('open');
ws.send('abcdefghijkl');
ws.send('abcdefghijkl');
ws.send('abcdefghijkl');
}
ws.onmessage = function(msg){
console.log('msg', msg);
}
</script>
</body>
</html>
'''
h = http.createServer (req, resp)->
return if req.url is '/ws'
resp.setHeader "Content-Type", "text/html"
resp.statusCode = 200
resp.end file
ws = qws.createServer h
ws.on 'connect', (msg) ->
console.log (123)
msg.write('data1asdlajsdlakjsdlaksjdlaksjdlaksjdlakjsdlakjsdlasjdlasjdlakjsdlaksjdl');
# setTimeout ->
# msg.write(fs.readFileSync('ordinary.txt'))
# , 1000
# h.listen 8081