Hello Team
I am using Xamarin tvOS framework for developing the tvOS project. So I am using the embedio nudget package as a local server. It is working fine when we launch the application. But when app goes into the background and app returns in ForeGround then embedio nudget package is not working as expected. It is started Giving the "System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error: ConnectFailure (Connection refused) ---> System.Net.Sockets.SocketException: Connection refused
at System.Net.Sockets.SocketAsyncResult"
I tried to dispose and again try to run the server but still it is not working and once we kill the application and again relaunch the app then it is working as expected.
So let me know If I am missing anything or If I am doing anything wrong here.
This bug has been reported before, issue #284. You can try changing the default HTTP Listener.
Unfortunately, I don't have a Mac to test in an iOS emulator.
@geoperez I tried the solution which is you suggested, I have used the "HttpListenerMode.Microsoft"
HTTP Listener mode but still I am getting the same error. Can you please take a look and suggest me any other solution for it.
Can you code run in Android?
@geoperez It is working fine in Android but it is giving too many exception in case of tvOS.
Can you share a sample project where to test in a Mac?
@geoperez Sorry I can not share the project information but I can share the other information like embedio (3.1.1) version.
Visual Studio Community 2019 for Mac
Version 8.3.11 (build 1)
Installation UUID: fca308dd-a4b6-466c-954d-fbfeb3bfc296
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 5.16.1.24 (d16-3 / 08809f5b)
Package version: 604000208
Mono Framework MDK
Runtime:
Mono 6.4.0.208 (2019-06/07c23f2ca43) (64-bit)
Package version: 604000208
NuGet
Version: 5.3.0.6192
.NET Core SDK
SDK: /usr/local/share/dotnet/sdk/3.0.101/Sdks
SDK Version: 3.0.101
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.4.0/lib/mono/msbuild/Current/bin/Sdks
.NET Core Runtime
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
3.0.1
2.1.14
Xamarin.Profiler
Version: 1.6.12.29
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
Updater
Version: 11
Apple Developer Tools
Xcode 11.3 (15712)
Build 11C29
Xamarin.Mac
Version: 6.6.0.12 (Visual Studio Community)
Hash: e3c2b406d
Branch: xcode11.2
Build date: 2019-11-01 00:12:07-0400
Xamarin.iOS
Version: 13.6.0.12 (Visual Studio Community)
Hash: e3c2b406d
Branch: xcode11.2
Build date: 2019-11-01 00:12:08-0400
Xamarin Designer
Version: 16.3.0.256
Hash: 8a223bfd7
Branch: remotes/origin/d16-3
Build date: 2019-11-01 21:02:02 UTC
Xamarin.Android
Version: 10.0.6.2 (Visual Studio Community)
Commit: xamarin-android/d16-3/c407838
Android SDK: /Users/apple/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
None installed
SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.2
SDK Build Tools Version: 28.0.3
Xamarin.Mac
Version: 6.6.0.12 (Visual Studio Community)
Hash: e3c2b406d
Branch: xcode11.2
Build date: 2019-11-01 00:12:07-0400
Xamarin.iOS
Version: 13.6.0.12 (Visual Studio Community)
Hash: e3c2b406d
Branch: xcode11.2
Build date: 2019-11-01 00:12:08-0400
Xamarin Designer
Version: 16.3.0.256
Hash: 8a223bfd7
Branch: remotes/origin/d16-3
Build date: 2019-11-01 21:02:02 UTC
Xamarin.Android
Version: 10.0.6.2 (Visual Studio Community)
Commit: xamarin-android/d16-3/c407838
Android SDK: /Users/apple/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
None installed
SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.2
SDK Build Tools Version: 28.0.3
Build Information:
Mono: mono/mono/2019-06@476d72b9e32
Java.Interop: xamarin/java.interop/d16-3@5836f58
LibZipSharp: grendello/LibZipSharp/d16-3@71f4a94
LibZip: nih-at/libzip/rel-1-5-1@b95cf3fd
ProGuard: xamarin/proguard/master@905836d
SQLite: xamarin/sqlite/3.27.1@8212a2d
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-3@cb41333
Microsoft Mobile OpenJDK
Java SDK: /Users/apple/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL
Android SDK Manager
Version: 1.4.0.65
Hash: c33b107
Branch: remotes/origin/d16-3
Build date: 2019-11-19 20:33:22 UTC
Android Device Manager
Version: 1.2.0.116
Hash: d2b2af0
Branch: remotes/origin/d16-3
Build date: 2019-11-19 20:33:42 UTC
Xamarin Inspector
Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1
Build Information
Release ID: 803110001
Git revision: 6ee6ad2ec46ae5a08a1999ee4c815ac656a35b91
Build date: 2019-12-05 16:09:27+00
Build branch: release-8.3
Xamarin extensions: 56bd70ef2e327f71c615cfc29a47fd50685fadcb
Operating System
Mac OS X 10.15.0
Darwin 19.0.0 Darwin Kernel Version 19.0.0
Wed Sep 25 20:18:50 PDT 2019
root:xnu-6153.11.26~2/RELEASE_X86_64 x86_64
My code for initializing web servers:
var server = new WebServer(o => o
.WithUrlPrefix(_url)
.WithMode(HttpListenerMode.EmbedIO))
.WithLocalSessionManager()
.WithWebApi("/", m => m
.WithController(() => new ProxyController(Settings, MulticastRetryProxy, StreamProxyService))
.WithController
);
// Listen for state changes.
server.StateChanged += (s, e) => $"WebServer New State - {e.NewState}".Info();
await server.RunAsync();
This is one sample method
[Route(HttpVerbs.Get, "/status")]
public object GetStatusAsync()
{
var status = new { active = "yes" };
return status;
}
I too see an issue with sockets on iOS. I believe I have I found the cause. Within the embedio logic (branch 3.X - version 3.4.2). Basically when a webserver is started and stopped, the sockets are not getting cleaned out and when the webserver is restarted, it appears they are getting reused. On Android,UWP this does not appear to cause any issues, but on iOS there is a case where this causes issues. On iOS, after a webserver is closed and the device is paused/put to sleep and restarted, the socket ends up in a bad state. Then when the webserver is restarted, that socket is reused, but because it is in a bad state, it causes the webserver to hang (in HttpListener:GetContextAsync).
What the issue is, is the cleanup logic on webserver stop looks to have a bug. Specifically, when the webserver is closed, EndpointManager.RemoveListener is called which calls EndpointManager.RemovePrefix. But in this code a new ListenerPrefix object is created and that is passed to the EndPointListener (EndpointListener.RemovePrefix).
The issue is in this code (EndpointListener.RemovePrefix). In that code it is looking at the passed in instance of ListenerPrefix to see if it exists in its dictionary (_prefixes). But since that instance is created and passed into this method, it will never find it in its local dictionary (_prefixes) and thus will not remove it. Then when CheckIfRemove is called, since the dictionary has a value (_prefixes.Count>0), the EndpointManager.RemoveEndPoint logic will never get called.
I have a solution that works by instead of checking for the passed in instance, check to see if the values have the same value, and do that by doing a string compare of the ToString() values of ListenerPrefix to find a match. I can create a pull request or fork with my changes for your review if you feel this is indeed an issue.
Thanks.
Can you share the pull request? I would like to see the change.
I have create a PR on my fork: https://github.com/unosquare/embedio/pull/463
Please let me know if you agree or would like me to make any modifications.
Can we close this issue?
@geoperez Is this issue resolve in the 3.4.3 version?
@desistud Do I need to change anything in my one for fixing this issue ?
Yes, the new version contains the fix from PR #463
@geoperez I tried with new version but still getting the same error, one more thing I am using tvOS not iOS.
Hello @rishabh14augshukla, thanks for using EmbedIO!
I'm closing this issue as it is a duplicate of #284. Please look there for a possible solution.