Headers Required for HandShake

botany02
@Kailash
Just developing my Own Websocket class for Kite Connect.
Im sending the following Header, but unable to handshake.
Getting error 'An Existing connection was forcibly closed by Remote Host"
This error indicates that the the Remote Host i.e. websocket.kite.trade unable to understand my Headers thereby closing the Connection.
Could You pls tell me Actual-Like-Example of Headers including mandatory and optional headers with brief info.
Below is what I'm Sending.

GET /?api_key=0eefvojtp9telqv1&user_id=AB1234&public_token=967bc35ce669bf009247c465fe7032d8 HTTP/1.1
Host: websocket.kite.trade:433
Upgrade: websocket
Connection: Upgrade
Origin: http://websocket.kite.trade
Sec-WebSocket-Version: 13
Sec-WebSocket-Protocol: chat
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==

Thanks
  • Kailash
    @botany02 Are you using a library that supports the WebSocket protocol? Simply sending the headers is not enough to establish a WebSocket connection.

    Does this help? https://msdn.microsoft.com/en-us/library/system.net.websockets.websocket(v=vs.110).aspx
  • botany02
    @Kailash
    the System.Net.Websockets is available from .Net 4.5 .
    But I'm trying to Implement my own class in .Net 4.0 using TcpClient.
    I can connect to my local server successfully but not with websocket.kite.trade.
    So Could You share the header details.?
  • Kailash
    Kailash edited October 2016
    @botany02 I recommend you use an existing library (there must be a 3rd party version) or you will have to implement the entire WebSocket protocol spec (https://tools.ietf.org/html/rfc6455)

    I don't think this will be of any help, but here are the headers Chrome sends when Kite connects. None of these headers are set by us. They're a part of the WebSocket spec.
    Accept-Encoding:gzip, deflate, sdch, br
    Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
    Cache-Control:no-cache
    Connection:Upgrade
    Host:websocket.kite.trade
    Origin:https://kite.zerodha.com
    Pragma:no-cache
    Sec-WebSocket-Extensions:permessage-deflate; client_max_window_bits
    Sec-WebSocket-Key:TmMWpj7LyD4duqXR3AZpww==
    Sec-WebSocket-Version:13
    Upgrade:websocket
    User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/53.0.2785.143 Chrome/53.0.2785.143 Safari/537.36
Sign In or Register to comment.