Giter VIP home page Giter VIP logo

eventsource4net's People

Contributors

erizet avatar sadfsadfasdf avatar yevster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

eventsource4net's Issues

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.

Exception throw when server is offline at start of eventsource

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

Any idea on how to port this .net 4?

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);

Connection closure

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

stop reconnect if server offline while running,

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)

EventReceived Callback never invoked

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":{}}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.