I use the socket net web library in my project. I do not want to use C # LightStreamer.
I connect to the push server using the following code, but it gives a connection error. I send all the headers but it does not connect to the server
var url = new Uri("wss://push.example.com/lightstreamer");
var factory = new Func<ClientWebSocket>(() =>
{
var client = new ClientWebSocket
{
Options =
{
KeepAliveInterval = TimeSpan.FromSeconds(5),
// Proxy = ...
// ClientCertificates = ...
}
};
client.Options.SetRequestHeader("Cookie", "_ga=GA1.2.383731026.1594794458; _gid=GA1.2.1818321527.1600487734");
client.Options.SetRequestHeader("Host", "push.example.com");
client.Options.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0");
client.Options.SetRequestHeader("Accept", "*/*");
client.Options.SetRequestHeader("Accept-Language", "en-US,en;q=0.5");
client.Options.SetRequestHeader("Accept-Encoding", "gzip, deflate, br");
client.Options.SetRequestHeader("Origin", "https://example.com");
client.Options.SetRequestHeader("Sec-WebSocket-Protocol", "js.lightstreamer.com");
client.Options.SetRequestHeader("Sec-WebSocket-Extensions", "permessage-deflate");
client.Options.SetRequestHeader("Pragma", "no-cache");
client.Options.SetRequestHeader("Cache-Control", "no-cache");
return client;
});
using (IWebsocketClient client = new WebsocketClient(url, factory))
{
client.ReconnectTimeout = TimeSpan.FromSeconds(30);
client.ErrorReconnectTimeout = TimeSpan.FromSeconds(30);
client.ReconnectionHappened.Subscribe(type =>
{
Console.WriteLine($"Reconnection happened, type: {type}, url: {client.Url}");
});
client.DisconnectionHappened.Subscribe(info =>
Console.WriteLine($"Disconnection happened, type: {info.Type}"));
client.MessageReceived.Subscribe(msg =>
{
Console.WriteLine($"Message received: {msg}");
});
Console.WriteLine("Starting...");
client.Start().Wait();
Console.WriteLine("Started.");
ExitEvent.WaitOne();
}