2

经过一些修改,这是我的 chrome 客户端和 java 服务器之间的转换:

GET / HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: localhost:4444
Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
Pragma: no-cache
Cache-Control: no-cache
Sec-WebSocket-Key: Gh/WYxZXrUNZdPc2+LQ/Tg==
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: x-webkit-deflate-frame
Sent text to CLIENT_1
-------------Response to handshake------------
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: NmkE36ZEsC5baQaMjLPb5CxHwDM=

握手答复由以下人员提供:

public static String Key(String thekey) throws NoSuchAlgorithmException {
    String base64;

    thekey = thekey + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
    MessageDigest md = MessageDigest.getInstance("SHA-1");
    byte[] digest = md.digest(thekey.getBytes()); // Missing charset
    base64 = Base64.encodeBase64URLSafeString(digest);
    base64=base64.replace("_", "/");
    base64=base64.replace("-", "+");
    return new String(base64);
}
 Send("HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: " + Key(key) +"=\r\n\r\n");

然后我可以发送 10 个字节的数据,然后客户端断开连接。我能做些什么?提前致谢!斯莫列特。

4

0 回答 0