erizet / eventsource4net Goto Github PK
View Code? Open in Web Editor NEWAn eventsource(Server-Sent Events client) implementation for .Net.
License: MIT License
An eventsource(Server-Sent Events client) implementation for .Net.
License: MIT License
What license is this project released under? I want to fork it and extend it to support ServiceStack's Server-Sent Event implementation but don't want to misuse it.
class WebRequester : IWebRequester
var taskResp = Task.Factory.FromAsync<WebResponse>(wreq.BeginGetResponse, wreq.EndGetResponse, null).ContinueWith<IServerResponse>(t => new ServerResponse(t.Result), TaskContinuationOptions.NotOnFaulted);
should TaskContinuationOption.NotOnFaulted, otherwise, exception throw
I'm trying to re-write this for the .net v4 framework as I need the app to run on Windows Xp. Yes, Xp.
The issue I'm having is with stream.ReadAsync below. Do you know the best alternative?
I tried to using the simple StreamReader but get timeout issues?
ConnectedState.cs 39-58
byte[] buffer = new byte[1024 * 8];
var taskRead = stream.ReadAsync(buffer, 0, buffer.Length, cancelToken);
try
{
taskRead.Wait(cancelToken);
}
catch (Exception ex)
{
_logger.Trace(ex, "ConnectedState.Run");
}
if (!cancelToken.IsCancellationRequested)
{
int bytesRead = taskRead.Result;
if (bytesRead > 0) // stream has not reached the end yet
{
//Console.WriteLine("ReadCallback {0} bytesRead", bytesRead);
string text = Encoding.UTF8.GetString(buffer, 0, bytesRead);
text = mRemainingText + text;
string[] lines = StringSplitter.SplitIntoLines(text, out mRemainingText);
Want co confirm that connection closure is not done yet.
using this lib on android and it seems like connection persist even after calling for cxltion token.
Can you please direct me on how disconnection can be achieved?
Thank you
class ConnectedState : IConnectionState
line 40 var taskRead = stream.ReadAsync(buffer, 0, buffer.Length, cancelToken);
taskRead IsFaulted due to the server disconnected.
fix
at line 50
if (!cancelToken.IsCancellationRequested && ! taskRead.IsFaulted)
Hi,
I am currently using your EventSource4Net for subscribing to SSE in c#.
It works fine for HTTP URL Ex http://testing.leadsquared.com:9090/Telephony/Configuration/Demo.
But in HTTPS it fails,Ex https://testing.leadsquared.com:9090/Telephony/Configuration/Demo.
Should i add anything explicitly to make it work?
By following the Sampe code I try to connect a Spring (Java) server using server sent events. The URL works fine using curl
but with EventSource4Net the EventReceived
handler is never invoked.
using EventSource4Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using slf4net;
using slf4net.Resolvers;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("start ...");
try
{
CancellationTokenSource cts = new CancellationTokenSource();
EventSource es = new EventSource(new Uri("http://localhost:9999/bus/api/v1/subscribe/karli"), 50000);
es.StateChanged += new EventHandler<StateChangedEventArgs>((o, e) => { Console.WriteLine("New state: " + e.State.ToString()); });
es.EventReceived += new EventHandler<ServerSentEventReceivedEventArgs>((o, e) => { Console.WriteLine("--------- Msg received -----------\n" + e.Message.ToString()); });
es.Start(cts.Token);
Console.WriteLine("EventSource started");
var a = Console.Read();
cts.Cancel();
}
catch (Exception ex)
{
Console.WriteLine("dasda {0}", ex);
}
}
private static void OnMessage(ServerEventMessage message)
{
Console.WriteLine($"OnMessage {message}");
}
}
}
prints:
start ...
slf4net: The factory resolver AppConfigFactoryResolver returned null from GetFactory(). The fallback no operation logger factory will be used instead.
Application information:
Application domain: ConsoleApplication1.vshost.exe
Application path: C:\Users\xxx\documents\visual studio 2015\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\
Machine name: XXX
EventSource started
New state: CONNECTING
New state: OPEN
After that nothing happens while I would expect the "--------- Msg received -----------\n" + e.Message.ToString()); to be printed as events are being sent
$ curl "http://localhost:9999/bus/api/v1/subscribe/karli" -v
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9999 (#0)
> GET /bus/api/v1/subscribe/karli HTTP/1.1
> Host: localhost:9999
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200
< Content-Type: application/stream+json
< Transfer-Encoding: chunked
< Date: Thu, 28 Jun 2018 05:00:01 GMT
<
{"key":"1","offset":3,"value":{}}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.