Closed Ruhrpottpatriot closed 7 years ago
Btw: I intended this as a starting point. There's still more room for improvement. For example, I find it a bit counter intuitive, how you handled the keep alive process. If I understood it correctly, you call OpenAnsyc()
and that Task only completes when the connection is closed.
Maybe change the code, so that every public async method accepts a CancellationToken
and the receive Task is decoupled from ConnectAsync()
.
TaskCompletionSource
could be an option. I'll look into it.
I intended this as a starting point. There's still more room for improvement...
Currently, cancel a task via token is the only way to close connection. Agree that this should be improved. I'll create a separate issue for this
This pull request added additional events for errors, open and close. These events and the OnMessage event now use the
EventArgs
orEventArgs<T>
type to pass along information to the subscriber. This allows the user to manage multiple socket connections and differentiate by sender.I also changed all event handler invocations (except
Close
) to be asynchronous, which was done with theTask.Factory.FromAsync()
method.Last I added a method to allow the user to add his own headers to the initial socket request. This allows greater flexibility with things such as authorization,