从 1.2.0 开始,getty提供了对websocket的支持。

    getty 基于java aio 对websocket协议进行了封装,对ws wss协议提供了支持

    同样的,getty已经对ws消息做了 粘包/拆包 。使用的时候无需考虑粘包/拆包的问题。

    1. * version 5+
    2. * 0 1 2 3
    3. * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    4. * +-+-+-+-+-------+-+-------------+-------------------------------+
    5. * |F|R|R|R| opcode|M| Payload len | Extended payload length |
    6. * |I|S|S|S| (4) |A| (7) | (16/64) |
    7. * |N|V|V|V| |S| | (if payload len==126/127) |
    8. * | |1|2|3| |K| | |
    9. * +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - +
    10. * | Extended payload length continued, if payload len == 127 |
    11. * + - - - - - - - - - - - - - - - +-------------------------------+
    12. * | |Masking-key, if MASK set to 1 |
    13. * +-------------------------------+-------------------------------+
    14. * | Masking-key (continued) | Payload Data |
    15. * +-------------------------------- - - - - - - - - - - - - - - - +
    16. * : Payload Data continued ... :
    17. * + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
    18. * | Payload Data continued ... |
    19. * +---------------------------------------------------------------+
    20. * version 1-4
    21. * 0 1 2 3
    22. * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    23. * +-+-+-+-+-------+-+-------------+-------------------------------+
    24. * |M|R|R|R| opcode|R| Payload len | Extended payload length |
    25. * |O|S|S|S| (4) |S| (7) | (16/63) |
    26. * |R|V|V|V| |V| | (if payload len==126/127) |
    27. * |E|1|2|3| |4| | |
    28. * +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - +
    29. * | Extended payload length continued, if payload len == 127 |
    30. * + - - - - - - - - - - - - - - - +-------------------------------+
    31. * | | Extension data |
    32. * +-------------------------------+ - - - - - - - - - - - - - - - +
    33. * : :
    34. * +---------------------------------------------------------------+
    35. * : Application data :
    36. * +---------------------------------------------------------------+