I am using Moonapns asp.net library to send push notifications to apple device.
it works fine on my local machine which is 64bit OS but when i am trying to deploy it to client's server with 64bit OS it gives following error , any one guide me what could be the problem?
Event log:
System.InvalidOperationException: The operation is not allowed on non-connected sockets.
at System.Net.Sockets.TcpClient.GetStream()
at MoonAPNS.PushNotification.OpenSslStream(String host, X509CertificateCollection certificates)
at MoonAPNS.PushNotification.Connect(String host, Int32 port, X509CertificateCollection certificates)
at MoonAPNS.PushNotification.SendQueueToapple(IEnumerable`1 queue)
at MoonAPNS.PushNotification.SendToApple(List`1 queue)
at NeoFaceWatchMobileClient.watchservice.Timer_Elapsed(Object sender, EventArgs e)
any help would be appreciated.
I guess it was due to server's restriction on that port that was being used by MoonAPNS, i asked network administrator and he removed the restriction and it worked, so it was not relevant to me or programming but server.
Related
SMBLibrary project on GitHub appears to be is exactly what I am looking for.
I need something to abstract a db to look like a file system, accessible via UNC path.
I am using Windows 10, Visual Studio as Administrator. I installed the MS Loopback Adapter, and disabled the other adapters. I have stopped the "Server" service.
Running the the server on 127.0.0.1, port 445 I receive the following error:
System.Net.Sockets.SocketException
HResult=0x80004005
Message=An attempt was made to access a socket in a way forbidden by its access permissions
Source=System
StackTrace:
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at SMBLibrary.Server.SMBServer.Start(IPAddress serverAddress, SMBTransportType transport, Boolean enableSMB1, Boolean enableSMB2, Nullable`1 connectionInactivityTimeout) in C:\Users\josep\Source\Repos\SMBLibrary\SMBLibrary\Server\SMBServer.cs:line 87
I am expecting to run the server app, then using explorer navigate to \127.0.0.1
It is not clear from Read.me if this is correct or not.
The readme is pretty clear on what you are doing wrong:
if you want localhost access from Windows explorer to work as expected, you must specify the IP address that you selected (\127.0.0.1 or \localhost will not work as expected), in addition, I have observed that when connecting to the first IP address of a given adapter, Windows will only attempt to connect to port 445.
You need to connect to the IP address assigned to the loopback adapter.
Background:
I am running a cross-platform Xamarin.Forms app on a Nexus 7 (Android API level 22) that is configured to (in order):
Connect to my WiFi network
Connect to a Python script that runs on the router/gateway (10.0.0.0/5000)
Connect to an A2DP Bluetooth audio receiver
on startup.
My development machine is running Windows 7 with Visual Studio 2019 Preview (v16.0.0 Preview 1.1), Xamarin.Forms (v3.4.0.1008975), and Xamarin.Android (v28.0.0).
The WiFi network is hosted by a Raspberry Pi 3 B+ running hostapd and dnsmasq on Raspbian Stretch. This access point hands out IP addresses in the range of 10.0.0.1 to 10.0.0.20, with a default gateway of 10.0.0.0. The network currently does not have Internet, but I may add it in the future.
The Pi also runs a script in Python which acts as a server for this app. The app is supposed to connect to this script via the .NET TcpClient so it can receive sensor data from the Pi.
The issue:
The app successfully connects to the WiFi and Bluetooth (steps 1 and 3), but I am getting a System.Net.Sockets.SocketException (HRESULT: 0x80004005) when it attempts to connect to the Python script (step 2). Here is the stack trace:
{System.Net.Sockets.SocketException (0x80004005): Network is unreachable
at System.Net.Sockets.SocketAsyncResult.CheckIfThrowDelayedException ()
[0x00014] in <165f7048c1ba483e8b4fcc215c691e9e>:0
at System.Net.Sockets.Socket.EndConnect (System.IAsyncResult asyncResult)
[0x0002c] in <165f7048c1ba483e8b4fcc215c691e9e>:0
at System.Net.Sockets.TcpClient.EndConnect (System.IAsyncResult asyncResult)
[0x0000c] in <165f7048c1ba483e8b4fcc215c691e9e>:0
at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic
(System.IAsyncResult iar, System.Func`2[T,TResult] endFunction,
System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult]
promise, System.Boolean requiresSynchronization) [0x00019] in
<76298308b9444eca9d8db328b3554473>:0
--- End of stack trace from previous location where exception was thrown ---
at Liberty_Console.Models.Statics+<ConnectAsync>d__2.MoveNext () [0x00052]
in C:\Users\Micah\Source\Repos\Liberty Console\Liberty Console\Liberty
Console\Models\Statics.cs:27 }
And this is the code that's causing it:
TcpClient client = new TcpClient(AddressFamily.InterNetwork);
await client.ConnectAsync("10.0.0.0", 5000); //System.Net.Sockets.SocketException
I have:
Ensured the app requests and receives these permissions:
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_WIFI_STATE
android.permission.BLUETOOTH
android.permission.BLUETOOTH_ADMIN
android.permission.CHANGE_NETWORK_STATE
android.permission.CHANGE_WIFI_STATE
android.permission.INTERNET
Ensured the tablet connects to the WiFi network and receives a valid IP address (10.0.0.X)
Ensured port 5000 is open on the router/gateway
Ensured the Python script is running properly (debugged from a Console App)
Tried pinging the router/gateway using the System.Net.NetworkInformation.Ping class
The request timed out
Researched the issue for a couple hours (to no avail)
My deduction:
Based on my tests and debugging, it seems like the app is unable to make requests on the network (hence it is "unreachable"). This may be due to:
How the WiFi network and subnet is structured (i.e. maybe the Android app is trying to run on 192.168.1.X instead of 10.0.0.X)
The fact that WiFi network does not have an Internet connection (so clients are limited to local networking)
An outgoing firewall/security measure in Android, Xamarin, or on the device itself
Differences between the TcpClient in Xamarin/Android and in the regular .NET framework
Any help is greatly appreciated!
Let me know if the question needs more detail or clarification.
This is a very popular topic here, and I have read at least twenty different stackoverflow, expertsexchange, codeproject "solutions", and they boil down to things like: proxy servers (which they assure me isn't being used), and other things that just don't help me.
I have an image that is sitting out on this server. It can be publicly reached through a URL (I won't give that here, being this is a customer server). The URL that is exposed is through a Virtual Directory that is set up through IIS.
I opened Visual Studio and created a new ASP.NET Web Application - and I made it an empty project, and added one WebForm to it. Simple as simple can be.
The only code I added was to the WebForm Page_Load function:
protected void Page_Load(object sender, EventArgs e)
{
using (System.Net.WebClient wc = new System.Net.WebClient())
{
Uri myUri = new Uri(#"http://SERVER/folder/Image.bmp", UriKind.Absolute);
byte[] bytes = wc.DownloadData(myUri);
}
}
That's it. That's all I do.
Because that URL is publicly exposed, when I run it in Visual Studio. It works.
Also, at work, I have a Web Server with IIS (The IIS that comes with Windows Server 2008 R2 Standard - Service Pack 1). I just copied my whole project folder (after I built for release), plopped it on inetpub/wwwroot/, went to IIS, added it as an Application (using annonymous access, and the Default App Pool).
Here, at work, no problem! No errors.
Now, I do the same thing to their server. Just take the whole folder. Create an application, etc. etc. .... and as soon as I get to the DownloadData piece of code I get an exception:
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 [redacted]:80
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: 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 [redacted]:80
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SocketException (0x274c): 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 [redacted]:80]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +8409635
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) +611
[WebException: Unable to connect to the remote server]
System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) +365
System.Net.WebClient.DownloadData(Uri address) +111
WebClientTest.WebForm1.Page_Load(Object sender, EventArgs e) in c:\Users\[me!!!]\Documents\Visual Studio 2013\Projects\WebClientTest\WebClientTest\WebForm1.aspx.cs:18
System.Web.UI.Control.OnLoad(EventArgs e) +103
System.Web.UI.Control.LoadRecursive() +68
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3811
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2053.0
So, to recap:
Simple project works in my debugging environment. Check!
Works on my server at work. Check!
Doesn't work on client server. Not Check!
There has to be some explanation for this. Obviously I can see the host. So why, when they host this code, instead of me, does it fail to establish a connection? Finding this information, or what can cause this, is surprisingly difficult. It has to be some type of server setting, right?
Their server is Windows Server 2012 R2 Standard.
EDIT: I also want to mention that I can open a browser anywhere (my desktop, my VM which hosts my debugging environment, their server, etc.) and if I take that URL, the bitmap displays. No problem. As soon as IIS/ASP.NET get involved ... connections fail. This is so discouraging.
EDIT2: I have a public facing cloud server, that has the same setup (same type of virtual directory, an image, etc). So I added a second WebForm to this project. Same code in PageLoad, this time pointing to my server for the image, instead of theirs. That page works! There's definitely something on their server that is causing this. But what?
We recently deployed a project into production and are now receiving this error message when we attempt to connect to the external sftp machine, "No connection could be made because the target machine actively refused it". When I was developing the application and testing it, we had no issues connecting to this server.
What would be different? I have administrative privileges and the app pool on the production server does not. I'm not sure if this could be what's causing the issue or if it may be something on the external client's server or their firewall blocking us.
If you are using localhost, specify 127.0.0.1 instead.
When I was using SSH.Net and the host was specified as localhost it threw the exception that the host actively refused the connection WSAECONNREFUSED - 10061. When I specified 127.0.0.1 instead, the connection could be made.
I think this is due to the implementation in SSH.Net:
internal static IPAddress GetIPAddress(this string host)
{
IPAddress ipAddress;
if (!IPAddress.TryParse(host, out ipAddress))
ipAddress = Dns.GetHostAddresses(host).First();
return ipAddress;
}
Which does not resolve a valid hostname for localhost, apparently. C# Interactive yields the following:
> Console.WriteLine(Dns.GetHostAddresses("localhost").First());
::1
The value ::1 does not seem to be a valid IP address for sockets to use.
This is a standard TCP error
WSAECONNREFUSED - 10061
From the Client's point of view it means 'there is no socket at that address listening to that port' (the "actively refused" is a red herring).
i) check the address
ii) check the port
iii) check firewall(s)
From our extensive experience (we offer own networking components) -- it's a firewall problem. The firewall doesn't let your requests pass. It's a common situation when you run say Putty, and it works, but your code doesn't. This is because many firewalls detect well-known applications and let them pass, while preventing other applications.
I have a Windows Service that does the following when started. When running via a Console application it works fine, but once I put in a Windows Service I get the below exception. Here is what I have tried so far:
Disabled the firewall, also tried adding explicit exclusions for the exe, port, and protocol
Checked CAS Policy Config, shows unrestricted rights
Configured the Service to run as an Administrator Account, Local System, Local Service, and Network Service, each with the same result
Tried different ports
Also tried 127.0.0.1 just to see... same issue
This is wrecking my head, so any help would be greatly appreciated:
The Code:
var _listener = new TcpListener(endpoint); //192.168.2.2:20000
_listener.Start();
The resulting Exception:
Service cannot be started. System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at System.Net.Sockets.TcpListener.Start(Int32 backlog)
at System.Net.Sockets.TcpListener.Start()
at Server.RequestHandler.StartServicingRequests(IPEndPoint endpoint)
at Server.Server.StartServer(String[] args)
at Server.Server.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)
I recommend you bind to an endpoint with IPAddress.Any (0.0.0.0) and a specific port.
The error message is likely because another application already has that port open or has recently had it open exclusively.
More information on the error code is on MSDN.