1iveowl / websocketclientlite.pcl Goto Github PK
View Code? Open in Web Editor NEWWebsocket client lite
License: MIT License
Websocket client lite
License: MIT License
I have a simple test app written in Xamarin for Android and connecting to my wss via ngnix.
In Ngnix if I set the following configuration, the app will error out when I enablethe ssl_cipher otherwise it would work well with TLS. My question is what is the strongest cipher that I can use for targeting Android 4.4 and above. The cipher suite works with a web browser websocket connection to the wss on the same server, so I know that my wss is working and the trouble would be the cipher suite for Android. Any pointer would be appreciated.
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
Thank you.
Hi
I have a json string greater than 126 characters but shorter than 1024 character in length, The problem is that the SendTextAsync is sending 0 bytes across to the websocket server. if the string is less than 126 chars then the server will receive it without problems.
How do I get around this without other complication? Thank you.
await websocketClient.SendTextAsync(jsonData);
Hi,
As the title already implied, I'd like to do a feature request regarding the TcpClient ownership handling in WebsocketClientLite. Currently, whenever one passes their own instance of TcpClient into the library, it will not get automatically disposed. However, I'd like to request a feature that does this regardless.
I currently pass my own instance into it in order to to create a proxied socket connection through Charles (an equivalent of Fiddler) so I can intercept all messages that are sent through the websocket. However, that results in me having to handle the disposing and closing of the websocket connection, which I honestly don't really know when to do properly, hence why transfering control to the library would solve that issue for me.
If anything is unclear or you would like to discuss this more, feel free to let me know. ๐
Hi,
I tried to use this library with Xamarin for Android. The nuget just hang there when I tried to install it via nuget. There is no further error or log that I can get beside the one below. I can install other nuget package like newtonsoft.json so I know that the connectivity to nuget is good. What could be wrong here?
Attempting to gather dependency information for package 'WebsocketClientLite.PCL.4.1.2' with respect to project 'TestApp', targeting 'MonoAndroid,Version=v8.0'
If I want to send the certificate exported: how would I do that? For example: My server accepts the connection only If I pass in a unique key. How can I send it via PCL lite?
When I try to install WebsocketClientLite.PCL 4.1.2 package in a .NET Standard 2.0 project in VS 2017, I get the following error message:
Detected package downgrade: NETStandard.Library from 2.0.1 to 2.0.0. Reference the package directly from the project to select a different version.
Test-> WebsocketClientLite.PCL 4.1.2 -> NETStandard.Library (>= 2.0.1)
Test-> NETStandard.Library (>= 2.0.0)
Package restore failed. Rolling back package changes for 'Test'.
I can successfully install the 4.1.1 package.
Looks like you refactored some code in develop.
This no longer works:
cts.Token.Register(() =>
{
_logger.Warn("Connection closed.");
disposeSubscriber();
onDisconnect?.Invoke();
});
client.OpenAsync() client.CloseAsync() client.OpenAsync()
Second open fails.
When I'm using SetRequestHeader(header.Key, header.Value);
not implemented exception thrown.
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for '<StartupCode$Examples>.$CobinhoodDemo' threw an exception.
Source=Examples
StackTrace:
at Examples.CobinhoodDemo.get_optionMap()
at Examples.CobinhoodDemo.BeginDemo() in C:\Users\preston\Development\NullVoxPopuli\CryptoExchangeClient\examples\CobinhoodDemo.fs:line 131
at [email protected](Unit arg00@) in C:\Users\preston\Development\NullVoxPopuli\CryptoExchangeClient\examples\Program.fs:line 12
at Chessie.ErrorHandling.Result`2.Try(Func`1 func)
Inner Exception 1:
FileLoadException: Could not load file or assembly 'ISocketLite.PCL, Version=4.2.1.0, Culture=neutral, PublicKeyToken=null'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I'm using a dotnetcore 2 app, and encounted this in debug mode when the flow of the program loaded a file that uses WebsocketClientLite.PCL.
I did a search for this: https://github.com/1iveowl/WebsocketClientLite.PCL/search?utf8=%E2%9C%93&q=ISocketLite&type=
but couldn't find it defined anywhere. Where is ISocketLite supposed to come from?
Here is the code:
https://github.com/NullVoxPopuli/CryptoExchangeClient/blob/f523faf7ed8de7fd54fc303ac78cce3e5f308ed5/src/exchanges/cobinhood/clients/WebSocketClient.fs#L13
I updated your nugget package https://github.com/1iveowl/WebsocketClientLite.PCL/blob/e159d85b4f2c67c7fa262e635383bae8c85424a5/src/main/Helper/ClientHandShake.cs
has default subprotocols added: Chat & Super chat. just FYI
Packages folder is missing when I downloaded the project again.
Hi,
I noticed that a new major build was released on NuGet a little while ago, however... I couldn't get the console test program to compile with the latest versions (7.0.0 and 7.0.1). Upon further investigation using the FuGet and NuGet package explorers, I noticed that the codebase looked pretty identical to the one of 6.4.0 which makes me want to believe that an issue happened somewhere during the upload to NuGet ๐
So it would be much appreciated if you could double check the NuGet releases as this looks like a really promising library.
Src: https://nuget.info/packages/WebsocketClientLite.PCL/7.0.1
Hello,
So far, I'm liking this library a lot.
A major issue I have though at the moment is when a connection to the internet is lost, or the far end drops the connection, I get an exception when I use SendTextAsync(String). It appears I can't catch the exception (or so far I haven't been able to). Any ideas how to work around this issue? To reproduce this, I simply disable my internet connection while sending messages
The exception I get is:
System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time,
or established connection failed because connected host has failed to respond.
---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time,
or established connection failed because connected host has failed to respond
at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
--- End of inner exception stack trace ---
at System.Net.Security.SslStream.EndRead(IAsyncResult asyncResult)
at System.Net.Security.SslStream.EndRead(IAsyncResult asyncResult)
at System.IO.Stream.<>c.b__43_1(Stream stream, IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory1.FromAsyncTrimPromise
1.Complete(TInstance thisRef, Func3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at WebsocketClientLite.PCL.Service.WebsocketListener.<ReadOneByteAtTheTimeAsync>d__26.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Reactive.PlatformServices.ExceptionServicesImpl.Rethrow(Exception exception) at System.Reactive.Stubs.<>c.<.cctor>b__2_1(Exception ex) at System.Reactive.AnonymousSafeObserver
1.OnError(Exception error)
at System.Reactive.Linq.ObservableImpl.AsObservable1._.OnError(Exception error) at System.Reactive.Subjects.Subject
1.OnError(Exception error)
at WebsocketClientLite.PCL.Service.WebsocketListener.b__27_1(Exception ex)
at System.Reactive.AnonymousSafeObserver1.OnError(Exception error) at System.Reactive.Linq.ObservableImpl.Where
1..OnError(Exception error)
at System.Reactive.Linq.ObservableImpl.Select2._.OnError(Exception error) at System.Reactive.ScheduledObserver
1.Dispatch(ICancelable cancel)
at System.Reactive.Concurrency.Scheduler.<>c.b__72_0(Action1 a, ICancelable c) at System.Reactive.Concurrency.DefaultScheduler.LongRunning.<>c__DisplayClass1_0
1.b__0(Object arg)
at System.Reactive.Concurrency.ConcurrencyAbstractionLayerImpl.<>c__DisplayClass7_0.b__0()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
IsConnected is never set to false after CloseAsync().
Hello,
I am trying to find a .Net Core compatible replacement for the websocket client for my Slack library http://github.com/noobot/slackconnector
When trying to connect to the Slack RTM I get a connection timeout (e.g. wss://mpmulti-q2ip.slack-msgs.com/websocket/xxxxxxxxyyyyyy)
Any idea what I am doing wrong?
System.TimeoutException : Connection request to server timed out
at WebsocketClientLite.PCL.MessageWebSocketRx.<ConnectAsync>d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at SlackConnector.Connections.Sockets.WebSocketClientLite.<Connect>d__7.MoveNext() in C:\code\slackconnector\src\SlackConnector\Connections\Sockets\WebSocketClientLite.cs:line 32
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at SlackConnector.SlackConnector.<GetWebSocket>d__6.MoveNext() in C:\code\slackconnector\src\SlackConnector\SlackConnector.cs:line 64
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at SlackConnector.SlackConnector.<Connect>d__5.MoveNext() in C:\code\slackconnector\src\SlackConnector\SlackConnector.cs:line 48
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at SlackConnector.Tests.Integration.SlackConnectorTests.<should_connect_and_stuff>d__1.MoveNext() in C:\code\slackconnector\src\SlackConnector.Tests.Integration\SlackConnectorTests.cs:line 24
at NUnit.Framework.AsyncInvocationRegion.AsyncTaskInvocationRegion.WaitForPendingOperationsToComplete(Object invocationResult)
at NUnit.Core.NUnitAsyncTestMethod.RunTestMethod()
I have just analysed my Nuget package using WebsocketClientLite.PCL and it says that the above inherited package isn't portable.
Are you aware of this?
https://icanhasdot.net/result?github=noobot~2Fslackconnector
Origin request header field should be settable to allow some CORS flexibility when connecting to third party servers.
https://tools.ietf.org/html/rfc6455#section-1.3
Good day,
Sorry if this is not the right forum to ask a question.
I am considering using this library for a websocket test client, similar to those that can be found as add-ins in Chrome etc. I would be wanting to create 100's of websockets at a time likely.
I'm curious if you have any idea how this library compares to the Microsoft client from a performance perspective, and if you think the threading should be ok to to start many websockets at a time.
Really appreciate the help,
Thanks you.
When I set it to ignore invalid ssl certs it seems to fail to do so. On .net core
Hello,
Sec-WebSocket-Protocol is aggregated wrong
See:
E.g: following line
List subprotocols = new List {"soap", "json"};
Will insert into the headers (wrong)
Sec-WebSocket-Protocol: , soap, json
Instead of (correct)
Sec-WebSocket-Protocol: soap, json
Possible solution:
var subprotocol =
$"Sec-WebSocket-Protocol: {subprotocols.Aggregate((current, protocol) => $ "{current}, {protocol}")}";
Hi, I use slackconnector (https://github.com/noobot/SlackConnector/) and it can't connect with proxy:
p.s. The error seems to be with the nuget library is WebsocketClientLite.PCL
System.InvalidOperationException
HResult=0x80131509
Message=The operation is not allowed on non-connected sockets.
Source=System
StackTrace:
at System.Net.Sockets.TcpClient.GetStream()
at SocketLite.Services.TcpSocketClient.d__19.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at WebsocketClientLite.PCL.MessageWebSocketRx.d__15.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at SlackConnector.Connections.Sockets.WebSocketClientLite.d__7.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at SlackConnector.Connections.ConnectionFactory.d__0.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at SlackConnector.SlackConnector.d__5.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at TopShelf2.SlackConnect.d__4.MoveNext() in C:\mygit\TopShelf2\TopShelf2\Program.cs:line 40
I think I posted this in the wrong repo, sorry - 1iveowl/SocketLite.PCL#5
Hello,
I am getting the following error when I run my integration test. Each test creates a new connection and closes it and I get the following intermittently:
Just had a quick read of the article you found. Via the tests everything is awaited on the same thread so wouldn't have thought that would cause an issue.
I am seeing it occur mainly on the TearDown. I am doing both a Dispose and a CloseAsync but looking at your library the Dispose doesn't do anything.
SetUp : System.AggregateException : One or more errors occurred.
----> System.NotSupportedException : The BeginWrite method cannot be called when another write operation is pending.
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at SlackConnector.Tests.Integration.IntegrationTest.SetUp() in C:\code\slackconnector\src\SlackConnector.Tests.Integration\IntegrationTest.cs:line 19
--NotSupportedException
at System.Net.Security._SslStream.ProcessWrite(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.BeginWrite(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback asyncCallback, Object asyncState)
at System.IO.Stream.<>c.<BeginEndWriteAsync>b__53_0(Stream stream, ReadWriteParameters args, AsyncCallback callback, Object state)
at System.Threading.Tasks.TaskFactory`1.FromAsyncTrim[TInstance,TArgs](TInstance thisRef, TArgs args, Func`5 beginMethod, Func`3 endMethod)
at System.IO.Stream.BeginEndWriteAsync(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.Stream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
at System.IO.Stream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count)
at WebsocketClientLite.PCL.Service.WebsocketSenderService.<SendFrameAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at WebsocketClientLite.PCL.Service.WebsocketSenderService.<ComposeFrameAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at WebsocketClientLite.PCL.Service.WebsocketSenderService.<SendTextAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at WebsocketClientLite.PCL.MessageWebSocketRx.<SendTextAsync>d__27.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at SlackConnector.Connections.Sockets.WebSocketClientLite.<SendMessage>d__8.MoveNext() in C:\code\slackconnector\src\SlackConnector\Connections\Sockets\WebSocketClientLite.cs:line 47
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at SlackConnector.SlackConnection.<Ping>d__54.MoveNext() in C:\code\slackconnector\src\SlackConnector\SlackConnection.cs:line 258
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at SlackConnector.Connections.Monitoring.PingPongMonitor.<StartMonitor>d__6.MoveNext() in C:\code\slackconnector\src\SlackConnector\Connections\Monitoring\PingPongMonitor.cs:line 33
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at SlackConnector.SlackConnection.<Initialise>d__36.MoveNext() in C:\code\slackconnector\src\SlackConnector\SlackConnection.cs:line 69
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at SlackConnector.SlackConnectionFactory.<Create>d__0.MoveNext() in C:\code\slackconnector\src\SlackConnector\SlackConnectionFactory.cs:line 14
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at SlackConnector.SlackConnector.<Connect>d__5.MoveNext() in C:\code\slackconnector\src\SlackConnector\SlackConnector.cs:line 58
--TearDown
at SlackConnector.Tests.Integration.IntegrationTest.TearDown() in C:\code\slackconnector\src\SlackConnector.Tests.Integration\IntegrationTest.cs:line 25
How do I can reduce the timeout period if the websocket service is down (the whole site gone AWOL) ?
Or is it possible to introduce a Cancellation Token ?
Currently it would take around more than 20 seconds for it it to error out and the await statement is blocking.
var messageObserver = await websocketClient.CreateObservableMessageReceiver(
new Uri("wss://myweb.com/ws:443"),
ignoreServerCertificateErrors: true,
headers: headers,
subProtocols: subprotocols,
tlsProtocolType: TlsProtocolVersion.Tls12);
Hi @1iveowl.
Have you tried connecting to a SocketIO server?
https://github.com/socketio/engine.io-protocol
I understand that SocketIO adds some overhead to the front of each frame, defining the packet types, which need to be parsed with a WebSocket implementation.
The current WebsocketClientLite.PCL source breaks in the HandshakeParser where the server sends a frame '0' for OPEN.
What is the best approach to support Socket.IO in your libraries? I am willing to help of course.
Thanks
Chris
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.