Skip to main content

Parse Handshake

Handshake is first thing before client and server establish connection. Handshake negotiate thress things:

  • protocol version - right now only version 1
  • data codec type - right now only support protobuf, value is 1
  • client platform - value is 9 as OpenAPI

So handshake is always fixed contents.

How TCP do handshaking

Client need send two bytes handshake to server.

Data structure

 0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+-+
| ver | codec |
+-+-+-+-+-+-+-+-+
|platfo.|reserve|
+-+-+-+-+-+-+-+-+

Fields Explain:

fieldlength in bitdescription
ver4protocol version: only value 1
codec4data codec: only value 1 for protobuf
platform4client platform: 0b1001 - OpenAPI
reserve4reserved

Example

  • ver - 0b0001
  • codec - 0b0001
  • platform - 0b1001
  • reserve - 0b0000

Two bytes contents:

0b00010001,
0b00001001

How WebSocket do handshaking

WebSocket send handshake info by URL Query

Query Parameters

FieldTypeDescription
version4protocol version: only value 1
codec4data codec: only value 1 for protobuf
platform4client platform: 9 - OpenAPI

Example

wss://openapi-quote.longportapp.com?version=1&codec=1&platform=9