I developed an application wchich is using sockets to connect with several servers. The application works fine with WI-Fi connection but crashes on 3g connection (of course on real device, on emulator everything works fine). I cannot debug it due to the fact that it works wken phone is connected to PC. How to handle this problem?
Thanks in advance
Subscribe to both Application.UnhandledException (for UI thread exceptions) and AppDomain.Current.UnhandledException (for all unhandled exceptions) and try to write to a file before your process is terminated.
After the application crashes, use the ISETool command line to copy the data back to your machine.
Application.Current.UnhandledException += (s,e) =>
WriteExceptionFast(e.ExceptionObject, "ApplicationUnhandled");
AppDomain.Current.UnhandledException += (s,e) =>
WriteExceptionFast(e.ExceptionObject, "AppDomainUnhandled");
private void WriteExceptionFast(Exception ex, String name)
{
string filename = Path.ChangeExtension(name, ".log");
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
using (var stream = store.CreateFile(filename))
using (var writer = new StreamWriter(stream))
{
writer.WriteLine(ex.ToString());
writer.Flush();
}
}
First: catch the exceptions and read them.
Secondy: I expect that you are running into not being able to connect to sockets due to firewalls protecting intranet machines from being accessed from outside.
Related
I have a Xamarin application that requires to connect to a device from the LAN side and also the WAN side. The device (an ESP8266) is connected via WiFi to an internal network and can be accessed from the WAN side via DDNS.
When the user makes a request (via the Xamarin app), whilst using mobile data (i.e. they are not connected to the WiFi network), the request reaches the IoT device (the IoT device makes a UPNP mapping on the router).
The IoT device uses mDNS to make itself known on the local network, and if I try to connect via Chrome on Windows 10 on a machine connected to the same network, the connection is successful (using 'domain.local'). Doing the same on on Chrome on Android gets a DNS error.
If the user now connects the phone to the same network as the IoT device, the Xamarin app request will no longer reach the IoT device. I have some code which distinguishes between a local request and a remote request which makes either a 'domain.local' request or a 'domain.ddns.net' request.
I understand the Apple Bonjour aspect of this on my desktop machine and the lack thereof on the Android platform.
Does anyone know how to resolve this?
So I have solved this and have posted the answer in case it's useful to someone in future.
Using the library Zeroconf https://github.com/novotnyllc/Zeroconf in Xamarin
private const string deviceHostName = "yourhostname"
public static async void GetDeviceIPAddress()
{
IReadOnlyList<IZeroconfHost> responses = null;
responses = await ZeroconfResolver.ResolveAsync("_http._tcp.local.");
foreach (var resp in responses)
{
if (resp.DisplayName == deviceHostName)
{
Debug.Print(resp.IPAddress);
}
}
}
Now making a http request to resp.IPAddress reaches the device advertising it's hostname as 'yourhostname'.
I am using an ESP8266 and it was important to start MDNS on the device BEFORE connecting the WiFi otherwise the device reports it's hostname as ESP_xxxx rather that 'yourhostname' which was the real root of the problem.
I need some help with the windows socket programming. I want to make a communication between an android phone (client) and a c++ application (server) with TCP over Bluetooth. On server-side I use windows sockets.
I already established a connection between both instances via RFCOMM but I want to make it over TCP/ IP. Does anyone know how I can create a Bluetooth socket under windows and send TCP messages over it?
Thanks a lot!
%*********** Update *************%
Recently, I tried to implement it via the windows stack. The connection is established but die communication is still rfcomm based. Does anyone know where my error or false thinking is?
serverSocket = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
// error checks
SOCKADDR_BTH sa;
memset (&sa, 0, sizeof(sa));
sa.addressFamily = AF_BTH;
sa.port = 11 & 0xff;
sa.serviceClassId = TCP_PROTOCOL_UUID;
bind(serverSocket, (SOCKADDR*)&sa, sizeof(sa) );
// error checks
// Register Service
WSAQUERYSET service1;
memset(&service1, 0, sizeof(service1));
service1.dwSize = sizeof(service1);
service1.lpszServiceInstanceName = _T("ViL Data...");
service1.lpszComment = _T("Pushing data to Android");
GUID serviceID1 = TCP_PROTOCOL_UUID;
service1.lpServiceClassId = &serviceID1;
service1.dwNumberOfCsAddrs = 1;
service1.dwNameSpace = NS_BTH;
CSADDR_INFO csAddr1;
memset(&csAddr1, 0, sizeof(csAddr1));
csAddr1.LocalAddr.iSockaddrLength = sizeof(SOCKADDR_BTH);
csAddr1.LocalAddr.lpSockaddr = (sockaddr*)&sa;
csAddr1.iSocketType = SOCK_STREAM;
csAddr1.iProtocol = IPPROTO_TCP;
service1.lpcsaBuffer = &csAddr1;
WSASetService(&service1, RNRSERVICE_REGISTER, 0)
// error checkings
This works all fine and I can connect to the server from my Android app. But I'm still confused why it doesn't transmit it over TCP. Can anyone help?
RFCOMM is an emulated serial port, it has nothing to do with Internet Protocols directly. You'd need to create a transport that runs over RFCOMM, e.g. a PPP connection. On Windows you'd do it by adding a new connection using the network settings from the control panel. The PPP would run over a null modem, essentially. Your application could do it programmatically, to, but it's a whole series of steps. Or, if you don't want to mess with Windows networking stack settings, you could embed a networking stack into your application and have it speak directly using PPP via the RFCOMM port.
I have a Visual Studio 2008 Team System C# solution running on my Windows 7 64bit box, and it has about 200 Selenium tests.
Until an hour ago most of the tests were okay, but suddenly none of the tests will run. They all give the same error:
System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:4444.
I'm using selenium-server-standalone-2.45.0, installed in ...\Program Files (x86)\selenium-remote-control-2.45.0
This has happened out of the blue, and I can't fathom out what might have changed. The code where the error is generated (this has been unchanged for years and usually works quite reliably) is:
public static ISelenium CreateDefaultSelenium()
{
string browser = ConfigurationManager.AppSettings["UnitTestBrowserString"];
if (browser == null)
browser = "*iexplore";
ISelenium selenium = new DefaultSelenium("localhost", 4444, browser, "http://localhost/");
return selenium;
}
public static void Start(this ISelenium selenium, int tries)
{
// Start the browser with a new Selenium session. Catch any WebException (eg socket refused) and retry a few times.
bool started;
int tryCount = 0;
do
{
tryCount++;
try
{
selenium.Start(); //<--this fails with the WebException
started = true;
}
catch (System.Net.WebException)
{
started = false;
if (tryCount >= tries)
throw;
}
} while (!started);
}
//start selenium at the beginning of each test:
ISelenium selenium = CreateDefaultSelenium();
selenium.Start(5);
and it throws a WebException with the error message I copied above.
I've ensured my local Windows firewall has port 4444 open for inwards TCP and UDP (it isn't usually), but that hasn't cured the problem. If I run the web application myself, it works fine so IIS is okay, although VS is using its own webserver. Rebooting has made no improvement.
Can anyone suggest what might have changed to cause this? I am at a loss as to where to turn next.
TIA
Okay, it turned out that amongst the Selenium log files there was a collection of lock files (selenium.log.1.lck etc). Deleting these immediately cured the problem.
Any chance of the Selenium team adding this gem to the Selenium documentation? It has taken me days to stumble onto this solution!
In my kernel extension I am currently supporting, I communicate with user spaces using sockets. So, I subscribe to some callbacks and correctly process them
reg.ctl_send = ctl_handle_send;
reg.ctl_getopt = ctl_handle_getopt;
reg.ctl_setopt = ctl_handle_setopt;
reg.ctl_connect = ctl_handle_connect;
reg.ctl_disconnect = ctl_handle_disconnect;
Everything works as expected. Only one problem - I can not unload my kernel extension if there are user space clients that are connected (ctl_deregister(kctlref) returns errors)
Is there a way to override it in kernel extension? I would like to disconnect from ALL clients and successfully unregister myself
On a Windows Mobile 6 device we are trying to open an internet connection. This usually works but sometimes we get a return code of 0x80004005 with a status of CONNMGR_STATUS_NOPATHTODESTINATION. When this happens it will keep happening but if you launch IE on the device, it will connect and then our call to ConnMgrEstablishConnectionSync works. We have not been able to isolate what causes this to happen, it currently appears to be random (though I suspect it isn't). Any hints?
Our code looks basically like this:
CONNMGR_CONNECTIONINFO connInfo;
DWORD dwStatus = 0;
memset(&connInfo, 0, sizeof(connInfo));
connInfo.cbSize = sizeof(connInfo);
connInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET;
connInfo.dwFlags = CONNMGR_FLAG_NO_ERROR_MSGS;
connInfo.dwPriority = CONNMGR_PRIORITY_HIPRIBKGND;
connInfo.guidDestNet = IID_DestNetInternet; /* Connect to the "Internet" network */
hr = ConnMgrEstablishConnectionSync(&connInfo, &s_hConnection, 120 * 1000, &dwStatus);
Windows Mobile connection manager is a huge PITA. Do you get the same error if you specify the network address by IP (e.g. "255.255.255.255/whatever") instead of by server name?
My guess is you could reproduce the lack-of-connection on demand with one of these methods:
Clearing the history in IE on the WM device
Closing IE from the running programs screen (in other words, really removing it from memory)
Soft resetting the device