-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Xamarin Android & Websockets #41835
Comments
SignalR uses System.Net.WebSockets so there shouldn't be any difference in behavior here. Can you share how are you using System.Net.WebSockets outside of SignalR? Also, capture client and server logs please: https://docs.microsoft.com/aspnet/core/signalr/diagnostics?view=aspnetcore-6.0 |
Hi @SSpormann. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
@BrennanConroy If I allow longpolling I get, And the connection is working, from here on. I used this example to validate that the concept should in theory work, https://devblogs.microsoft.com/xamarin/developing-real-time-communication-apps-with-websocket/ (You will have to Update some/all nuget packages to make it work) Maybe it has something to do with teh setup of my project, the client is currently in a netstandard 2.1 project that I referenced in my project, beacause we are using the same client on multiple platforms. If I use the same client under WPF, with only transport Websocket, every thing works fine. |
I can now provide a sample that shows a working version with playn websockets, and a version that is working with signalr Longpolling enabled and is not working with signalr only using websockets on the client side. You can finde the project here: If you prefere an other methode to recieve the sample please, contact me we can figure something out. To use the sample there is a solution under the folder easychat, there should be two Xamarin projects inside, one is called MyEasyChat, this is using plain websockets, combine this project with the server in the folder myeasychat und you can see that the concept of using websockets with System.Net.WebSockets does work. If you now want to try the faulty projekt, you have to use the project SignalRMyEasyChat under the EasyChat.sln and combine this with the myeasychat-signalr server under the folder with tehe same name(myeasychat-signalr) this, should currently promt the same error as I provided earlier.
if you now change the line of code in the EasyChat.sln -> SignalRMyEasyChat -> ChatPageViewModel line: 41 From: To: you should see that Signal-R is indeed working, but it does not work with websockets as transport. you will have to change the IP-Adresses, in the ChatPageViewModel files, to your Server-IP. I would investigate this problem further by my self but, currently I have no Idea how to setup the aspnet core repository in a way, that I would be able to debug this problem, I tried to setup a debug environment a year ago and stoped trying after 2 days. If someone has a guide on how to debug the aspnet.core project that would help me out a great deal. I allso tryed to capture network traffic, from the phone to the server and as I suspected earlier, there is not even a connection request exiting the device, so I belive ther must be a logic error that throws the exception client side. |
Please provide the repro app as a github repository. |
@BrennanConroy here you go. |
@SSpormann is it private? It says not found. |
@BrennanConroy sorry should be public now |
Why would you allow the client to send a message of 1GB? That's a potential security issue. |
Also unrelated, sent a clean up PR SSpormann/EasyChat-SignalR#1 |
@SSpormann can you remove specifying all of the transports from both the client and server? |
@davidfowl No thats the point of the sample, i want to use websocket transport, if i use longpolling it works, and if I remove the Settings from the client it falls back to longpolling |
WebSockets is used by default, when nothing is specified. We're trying to understand why that isn't happening in this case. |
So if i remove the transport overwrite from both, the client and the server it defaults to server sent events
|
Great, so it's explicitly always skipping websockets. What server are you running this on? |
In testing I use a Windows 10 mashine, but in production we use Ubuntu 20.04 lts and it shows the same behavior |
Those are wildly different OSes, so before debugging, we should pick the relevant one and the one you have access to. Though since it happens on both I wonder if this is a client problem more than a server one. What do the server side logs show when you try to connect? |
As I mentioned earlyer in the post, I head a suspicion that this is a client problem if I define only Websocket transport on the client I don't get a request on the server, I allso tried to log the network traffic, but there was no request on the signalr port, so I figured the client side must have prevented the execution of the request. so if I dont configure transport, I get
If I do, specify websockets, I dont get anything. |
This is the only thing that comes to mind Line 44 in 0af1274
How easily can you debug first chance exceptions in Xamarin applications? |
Does console logging work with Xamarin android? If yes, you should be able to use this package to add the console logger to the |
I never tried this, without putting the source directly into my solution, but I dont know if i could link the pdb of the asp signalr project, this might work. Yes the overwrite logging should work. |
@SSpormann Lets go with the client side logging for now. That should suffice. |
This is unconfigured this is configured with websockets only |
Seems like HTTPS is the problem? The error is right there:
|
Yes i have seen the error, but the same seems to work with ather transports they should in theory use the same implementation of SSL as longpolling and serversendevents, but this must than be an issue of googles boringssl. |
Try adding this to your client configuration: opts.WebSocketConfiguration = o =>
{
o.RemoteCertificateValidationCallback = (a, b, c, d) =>
{
return true;
};
}; OR you can use HTTP instead of HTTPS.. 😄 |
@BrennanConroy I tryed that before, It does work if you dissable SSL but it did work without SSL before, and not using encryption is not a vallid solution for production. |
If your repro is small enough to translate, you might want to try it as a The sockets layer was completely rewritten for .NET 6 Android and is now much closer to the rest of .NET. It might help narrow down which component is causing issues. |
Hi @SSpormann. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate. See our Issue Management Policies for more information. |
@davidfowl i have tried this, not on maui, it does not help. |
@jpobst i might consider rewriting the sample application, but currently i dont have the time to convert the production app to maui, and in the current state of the maui project I'am hesetant to do so in production. |
Triage notes: We think the support for self-signed certs for WebSocket and gRPC (because of HTTP/2? @JamesNK) on android might be lacking. It is interesting that "normal" long polling and SSE requests still worked. Edit: Is this multiple issues? What about publicly signed certs? What CA list does SslStream use on Android by default? It doesn't look like we're using OpenSSL like we would on a conventional Linux distro. Context: dotnet/runtime#45741 |
@halter73 I have the same scenario in production with Letsencrypt certificates, so I dont think this is nescessarily the problem. |
dotnet/runtime#74292 is another issue dealing with TLS problems on Android. |
Thanks for contacting us. |
My xamarin app was working for a while now but after i upgraded ,Net 6 on the server. Then this error started happening. Unable to connect to the server with any of the available transports. (WebSockets failed: Unable to connect to the remote server) (ServerSentEvents failed: Response status code does not indicate success: 404 (Not Found).) (LongPolling failed: Response status code does not indicate success: 404 (Not Found).) |
So i finally came arround to convert my existing production app to MAUI and lo and behold the issue is resolved and my project works as excpected and predicted by @jpobst I consider this problem solved. |
Is there an existing issue for this?
Describe the bug
I am trying to support websockets with signalR 6 on Android, with a Xamarin app, my code works as intended with longpolling, but there are clear benefits for me in using websockets, and I now have tried for a long time to make this work. But if I set supported transports to Websockets only in the client I get the error message that Longpolling is dissabled in the client, but the server does provide Longpolling,
Unable to connect to the server with any of the available transports. (WebSockets failed: Unable to connect to the remote server) (LongPolling failed: The transport is disabled by the client.)
My client, does look like this;
and the Server is configured like this:
services.AddSignalR().AddHubOptions<RabbitHub>(options => { options.MaximumParallelInvocationsPerClient = 32; options.KeepAliveInterval = new TimeSpan(0,0,0,5); options.ClientTimeoutInterval = new TimeSpan(0,0,0,10); });
endpoints.MapHub<RabbitHub>("/rabbitHub", options => { options.Transports = HttpTransportType.WebSockets | HttpTransportType.LongPolling | HttpTransportType.ServerSentEvents; });
Expected Behavior
The Expected behavior would be that the client would be aple to connect to the SignalR Server via websockets, this seems to be no Problem with Android, if I connect to an non signalR Websocket I with System.Net.WebSockets, everithing is working as intendet.
So there has to be a bug in the Aspnet.core lib.
I'am using this lib with netstandard 2.1 for the client and .net6 for the server, but changing the server from 5 to 6 did not change anything.
Steps To Reproduce
I would like to provide a simple example, I will provide one as soon as I , find the time to Build one.
Exceptions (if any)
Unable to connect to the server with any of the available transports. (WebSockets failed: Unable to connect to the remote server) (LongPolling failed: The transport is disabled by the client.)
.NET Version
6
Anything else?
No response
The text was updated successfully, but these errors were encountered: