Closed Raj123456788 closed 7 years ago
Not sure I have not seen that issue, but here are some ideas.
The library depents on System.Reactive - i.e. Reactive Extensions (Rx). There was a change in namespace from 2.2.5 to version 3.0. If you already have an earlier version of Reactive Extension install I suggest removing it and reinstall System.Reactive 3.0.0.
For more details look here: https://www.dotnetfoundation.org/blog/rx-net-welcome
Regarding adding a sub.protocol I am not sure what you mean by that question, can you elaborate a bit?
if I need to add a header how do I add it? In Header method of MessageRx class.
For details: https://github.com/Atmosphere/atmosphere/wiki/Writing-WebSocket-Sub-Protocol Something like this: https://github.com/fredrikslattman/websockets-subprotocol-example/blob/master/README.md
Thanks!
Try and take a look/download at the develop branch.
I've tried inplementing sub protocols. Unfortunately I haven't found a way to test it. Do you have a way of testing this?
Also, I fixed the reference error in Test Console. Apologies for that.
Sure, I will test it on Monday and get back to you. Thank you so much. Just a suggestion: Can you please add test solution for all platforms running a simple test!
Perfect.
If it does not work, could you please share a websocket endpoint so that I can test against it.
Regarding more platforms it should be the same code for UWP etc. but if you want to add feel free to do a Pull Request against the develop branch.
Hi There, I cannot share the websocket endpoint since it is on private n/w. My apologies! I will try with other platform and keep you updated. Thank you so much!
Hmm. First of all it looks like you're not using the latest version as I'm now using: ContainsKey("SEC-WEBSOCKET-PROTOCOL");
- i.e. capital letters.
I made some changes. Try get the lateste version of the develop branch or get the Nuget versiojn 2.0.1 that I released a few minutes ago.
Let me know how things play out and send me copy of any Exceptions you might see.
Sir, for Android some reason :await websocketClient.ConnectAsync( new Uri("wss://IPAddress/"), cts, ignoreServerCertificateErrors: false, subprotocols: subprotocols); Exception: Unable to acquire a lockedBuffer, very likely client tries to lock more than maxImages buffers Unhandled Exception:
System.IO.IOException: The authentication or decryption has failed.
" at Mono.Security.Protocol.Tls.SslStreamBase.EndRead (System.IAsyncResult asyncResult) [0x00051] in…"
Thread finished:
waiting for your response! How will you use self signed certificate with your library?
Hi Raj,
I appreciate your feedback and I want to help you and I want to make the library better and fix bugs. Now, I'm not sure what time-zone you are in, but I'm in Europe CET+1. Writting this library is a hobby (as in I don't get paid doing it) and not a day job . So, I do this in the evening. It is evening where I now ;-) So let's look at it.
Firstly, is it correctly understood that the sub-protocol now works for you - on Windows at least?
Have you tried setting ignoreServerCertificateErrors: true
? Now, you might not want to do this in a production system, but if it works with the true setting in test, that might indicate that the error is related to som SSL/TLS certificate issue.
What version of the Android SDK har you using? And What version if Java? What version of Xamarin?
I'll be waiting for your response to the above too ;-)
Meanwhile I will take a look at SocketLite.PCL, on which this library is based. I have a hunch that this might be the origin of the challenge, now that it works on Windows and not Android.
Hello Friend, my apologies if you thought I am hurrying up on you!! I tried ignorecetficateErrors:true but still the same error :(. I am using jdk1.8.0_77 && android-24., Xamarin-4.2.
Is there a way I can do this like java code below. SSLContext secureContext = NaiveSSLContext.getInstance("TLS"); wsFactory.setSSLContext(secureContext);
Someone did this in other project and it works for that websocket Library. A way to self sign the certificate.
Thank you for writing this Library!
No problem ;-)
I've tried to recreate the exception, but so far with no luck. In fact I don't get any exception, but I don't get any websocket connection either. It just doesn't do anything.
I am however, quite sure that the issue is related to the SocketLite.PCL library so I need to look more carefully at that.
I'm going to need some more time to track down this bug. I'll let you know when I make progress.
Ahh, this could be it: Mono Now Comes With Support For TLS 1.2, October 1st. 2016.
There is also this recent post on the subject: Enabling TLS 1.2 in Xamarin.Forms
The SocketLite.PCL library is set up to use TLS 1.2, but Mono's support for TLS 1.2 is very recent and have probably not yet found it's way into the latest Xamarin version.
I need to test this. It's too late to do that today. I will get make when I have had the opportunity to look at it.
Cool, found this link. Is there any way you can add capablity to edit ServerValidationCallback (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
I've implemented the ServerValidationCallback and I have some good news and some not so good news.
Firstly, I've tracked down the bug to this line of code:
secureStream.AuthenticateAsClient(address, null, tlsProtocol, false);
This is in the SocketLite.PCL library. And when the Client get to this place nothing happens for Android (and also iOS I believe as oOS also rely on Mono) it just get stuck.
Things work fine with .NET as you have also experienced.
Secondly, the issues seems to be originating from Mono. And that is the bad news, as I don't know how to fix the bug. I've asked the question: SslStream AuthenticateAsClient hangs
I've filled a bug to Mono: SslStream AuthenticateAsClient hangs
Thanks. If there is any documentation you could point me. I will try to get some answers!
Not sure what you mean by documentation, but you can read more about Mono here: The Mono-Project - Cross platform, open source .NET framework
Mono is basically the .NET framework implemented on none Windows platforms. Not to be confused with .NET Core, which is also cross platform, but is a sub-set of the .NET Framework geared towards Server-Side.
Another question: Does Sub-protocol work now for you on .NET/UWP Windows?
Sorry for late reply. yes,sub-protocol works on .NET not sure about UWP. Just saw the other question about headers and I was thinking how would some one do this using PCLlite? Subprotocol is different than adding a header?
Yes, please start a new tread. This keeps things neat ;-)
Found this link: https://github.com/rdavisau/sockets-for-pcl/issues/35 Checkout this comment: ModernHttpClient avoid any of these limitations as it wraps around native-based iOS and Android http libraries, bypassing the mono-based implementation completely. The equivalent here would be implementations for TcpSocketClient and friends that use the standard iOS framework socket (or a suitable third party wrapper) and the same for Android's java implementation. It would not be a trivial amount of work so I think it will be worth getting a better idea of what the status of the mono fixes are in the first instance. I'll do a bit of research.
I tried changing TcpSocketClient to Mordernhttp but looks like a major refactor :(
Yes, this is also my conclusion. It's the mono library that is the issue.
It does look like they are working on it: Release Notes Mono 4.6.0.
You can't change TcpSocketClient to ModernHttp. The first works on the TCP layer and the second further up the stack on the HTTP layer.
If the ModernHttp code is Open Source, you could try and figure out how they manage the SSLStream to get around the limitations, but I would assume that this is quite advanced. However, I have not looked at it.
yup!
Hi, So this bug is fixed in mono 4.6.0 but since Xamarin is still running few versions there is no way to fix this?
So far my testing have come up negative. However the release not also state that this is early work. So no not yet I guess.
Can you please explain the testing part? I did not understand that.
I have tried with Android running Nougat 7.0 as I understand that this version runs Mono 4.6.0 but I'm still unable to astablish an a connection to a Websocket server using TLS 1.2.
Just curious: Did you try setting MONO_TLS_PROVIDER environment variable?
Yes, that was the purpose of the test.
I added it by adding a the file "EnvironmentVariables.txt" to the project. I even tested that it was set - see line 146 of TcpSocketClient - and it was. (Note: the line is commented out now, but if was not commented out when I did the test).
FYI: Updated Xamarin. Release notes says: Mono 4.6.1 but issue still exists https://releases.xamarin.com/
Yeah, looks like they are aware of the issue and are working hard to fix it. With a little luck it will be fixed in a month or two.
Raj,
Have you tested this with the latest release of the WebsocketClientLite v3.6.1-beta4 and with Mono 4.6.2.7?
Hey, how are you doing? No I have not. Any indications of bug being fixed?
Only indication is that it was previously flagged as a bug so I suppose that eventually it will be fixed.
Also, I've made quite a bit of changes to the library over the past weeks so I might have fixed it.
I'm currently now running in a dev system that supports Android so I can't test it myself.
Hi there, I sit next to Raj at the company we work for, and wanted to get in on help testing out the TLS issues in mono.
I see that you're using the NETStandard 1.2 for the 3.6.2 version of teh WebsocketClientLite.PCL, which is either profile151 or profile44. I tried installing WebsocketClientLight.PCL using both profiles, but I'm still getting this nuget error:
"Could not install package 'SocketLite.PCL 3.6.2'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.6,Profile=Profile44', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author."
Which profile should I be using to install your websocket lib into a PCL?
thanks much!
That is because SocketLite.PCL 3.6.2 does not support any of the two profiles.
SocketLite supports:
It does not support Windows 8.x. or Windows Phone 8.x.
The tricky part here is that SocketLite.PCL is a Bait and Switch PCL and not a clean-cut .NET Standard library. I wish that i could be, but there are pieces missing in .NET Standard related to the Network layer that prevents this. I hope that this will go away as .NET Standard 2.0 is releases, however I doubt that Windows 8.x or Windows Phone 8.x will be supported there either - but I don't know that.
My apologies for the inconvinience, but this is the best I can do at the moment.
Do you really need Windows 8.x and Windows Phone 8.x support?
Hi Thanks for that info... Actually, I'm not supporting Windows 8/8.1 or WP8.1, so all I'll need to do is re-target my PCLs to use the NETStandard 1.6, yes?
One more question, if I target the .NET Standard 1.6 so I can use the websocketlite, I won't be able to reference Xamarin.Forms in that PCL, correct? I think XF is profile111 or profile151 only.
Xamarin Forms should be ok, and you don't to go all the way to .NET Standard 1.6. .NET Standard 1.2 should do it.
Try and see here:
Here is one more: Using Xamarin Forms with .NET Standard
Yes that helps tremendously, thank you!!!
Ok, I've got my entire solution converted over using .NET Standard based PCLs, so adding a reference via nuget for WebsocketClientLite works as expected.
Unrelated to my previous questions, I don't see any API's for when a socket is successfully opened. In your example, you invoke ConnectAsync, then you start sending data. Am I missing something?
In a simple workflow, I would expect to be able to attempt a connection specified by using a timeout, then upon successful connection, I would commence with sending data...
Am I supposed to use a while-loop and inspect the IsConnected property?
Not quite sure I understand and I don't have access to my PC right now.
Anyhow, you should be able to use Reactive Extensions and just subscribe to the messages that come in. Try and look at the Test code. It's a bit of a mess right now, ut I think you can get the idea.
Thanks! Got it. I subscribed to the 'ObserveConnectionStatus'.
Exactly. Yes, that will tell you the status of the connection ;-)
I need to update the readme.
I copied the demo in Program.cs and created a new .NET Core Console app. Added the correct .NET Standard1.4, and received the Bait & Switch error message.
Then I created a new Xamarin.Forms app, changed the PCL to .NET Standard, modified the project.json file accordingly, added your Program.cs code, and received the Bait & Switch error.
Fianlly, created a classic ConsoleApp, added the WebsocketClientLite nuget, ran it with no errors.
Here is my project.json, does it look correct to you?
{ "supports": {}, "dependencies": { "WebsocketClientLite.PCL": "3.6.2", "Xamarin.Forms": "2.3.3.175", "NETStandard.Library": "1.6.1" }, "frameworks": { "netstandard1.4": { "imports": "portable-net45+win8+wpa81+wp8" } } }
Hi,
I just tested this. I created a .NET Core Console App. Added WebsocketLite.PCL v.3.6.2 from Nuget and it wroked fine. It is important that you use the nuget. You cannot just reference the project locally as Bait and Switch will not work in that case. Nuget is doing some of the work.
Also, I am using the latest Visual Studio 2017 RC build 26014. You don't have to use that but if you do you for some reason have to manually add NETStandard.Library (currently version 1.6.1).
Same thing with Xamarin Forms. Are you sure you are adding WebsocketLite as a Nuget?
Does this help?
I get above error when I downloaded the solution.
Also, how would you add sub-protocol to a websocket connection?
Thank you so much for writing this Library.