// As Client private RequestHandshake createOpeningHandshake() { var path = _uri.PathAndQuery; var host = _uri.DnsSafeHost; var port = ((System.Net.IPEndPoint)_tcpClient.Client.RemoteEndPoint).Port; if (port != 80) { host += ":" + port; } var req = new RequestHandshake(path); req.AddHeader("Host", host); req.AddHeader("Sec-WebSocket-Key", _base64key); if (!Ext.IsNullOrEmpty(_protocols)) { req.AddHeader("Sec-WebSocket-Protocol", _protocols); } req.AddHeader("Sec-WebSocket-Version", _version); if (!string.IsNullOrEmpty(this._origin)) { req.AddHeader("Origin", this._origin); } //extra headers if (this.ExtraHeaders != null) { foreach (var i in this.ExtraHeaders) { req.AddHeader(i.Key, i.Value); } } return(req); }
private void close(ushort code, string reason) { var data = new List <byte>(Ext.ToBytes(code, ByteOrder.BIG)); if (!Ext.IsNullOrEmpty(reason)) { var buffer = Encoding.UTF8.GetBytes(reason); data.AddRange(buffer); } var payloadData = new PayloadData(data.ToArray()); if (payloadData.Length > 125) { var msg = "A Close frame must have a payload length of 125 bytes or less."; onError(msg); return; } close(payloadData); }