0
TL; DR: 通過Web套接字向客戶端發送「Deflate」壓縮數據導致難以追蹤的問題。是否可以通過Web套接字發送「Deflate」壓縮數據?通過網絡套接字發送壓縮數據(至Flash VNC應用程序)
我有一個應用程序使用已更新爲使用Web套接字的Flashlight VNC。爲了使其更具性能,我試圖在數據到達Flash應用程序之前對其進行壓縮。握手後(即壓縮開始時),VNC客戶端立即炸彈。
握手:
'Upgrade: WebSocket\r\n' +
'Connection: Upgrade\r\n' +
'Host: ' + hostport + '\r\n' +
'Origin: ' + url.slice(0, url.indexOf("/", 10)+1) + '\r\n' +
'Sec-WebSocket-Protocol: ' + 'base64' + '\r\n' +
'Sec-WebSocket-Key1: ' + key1 + '\r\n' +
'Sec-WebSocket-Key2: ' + key2 + '\r\n\r\n';
壓縮代碼(斯卡拉)
def deflate3(str:String):String = {
val data = str.getBytes
val deflater = new Deflater
deflater.setInput(data)
val outputStream = new ByteArrayOutputStream(data.length)
deflater.finish
val buffer = new Array[Byte](1024)
while(!deflater.finished) {
val count = deflater.deflate(buffer)
outputStream.write(buffer, 0, count)
}
outputStream.close
outputStream.toString
}
腹板套接字發送(嵌入式碼頭8 /斯卡拉):
def onMessage(message:String) {
try {
val compressed = deflate(message)
serverSocket.connection.sendMessage(compressed)
} catch {
case e : Exception => {
println(e.getCause)
}
}
}