Connect to attached pc from WP7 by opening a socket to localhost - sockets

When developing and testing WP7 apps you're pc is connected to either a real WP7 phone or to the WP7 Device Emulator. For a specific development-purpose I would like to connect directly to the development pc (let's call it the host pc) from the WP7 app without having to rely on an external toast-server. I'm using plain sockets, System.Net.Sockets.Socket.
There seem to be two options:
Obtain the host pc's LAN IP and connect to that
Connect to localhost
Option 1 usually works well, but not always: The host pc may not necessaily have an IP, in which case there's nothing to connect to. Also, in some scenarios all LAN traffic is directed through a company-wide proxy which will disrupt this mechanism.
That lead me to try out option 2. To my surprise it seems to work, but I need to be more sure than simply "it seems to work". I've googled all over but can't find any definitive answer, not even on Microsoft's site like e.g. http://msdn.microsoft.com/en-us/library/ff754351(v=VS.92).aspx. So this is my question:
What exactly is the defined behavior of connecting to localhost from a WP7 app?
Altrernatively, is there a fool-proof way of connecting back to the host-pc?
(Let me stress this again: For this particular purpose I can't use toasts, because the development pc may not even be online.)
Edit:
I work at EQATEC and the application in question is the EQATEC Profiler. Right now the profiler/app-communication is handled by injecting a socket/http-client into the deployed WP7 app that connects back to the profiler's LAN IP address. It works very well and is really fast, but in some very rare cases users are offline and therefore doesn't have an IP, or have some prohibitive lan proxy rules.
Therefore connecting to "localhost" would be excellent if that somehow magically would always work for everybody. It works for me and a couple of test-users, but does it work for all our many thousand profiler users all over the world? I'd like to be more sure.

"localhost" by definition is the machine running the code (well specifically the NIC doing the communication). For either the Phone or the Emulator, that would mean the phone or the emulator, not the PC they are attached to.
When you attach to a PC, you do have a network - it's an RNDIS connection in which both sides get an IP address which traditionally (pre-WP7) could be resolved with 'ppp-peer', though I've not tested that resolution on the Phone. I suspect it will be the same, since WMDC is still what's connecting and they'd have little reason to change that connection mechanism.
If the emulator is resolving localhost to the PC on which is resides, that's a definite bug and I would not count on it continuing to work as they add more robust socket support to the Phone platform.

System.Net.Sockets.Socket isn't really currently available for WP7 programming, but it might be available at some future point (maybe in Mango... maybe...)
AFAIK, the only way to reliably do what you want to do is to set up an http server on the development PC and to provide your app with an HTTP address of that server - or to route messages via some "Cloud proxy"
I'm surprised localhost works at all on the real device... I can only assume that they are asking the connected PC to resolve that DNS name - but even then I'm surprised 127.0.0.1 works.

The ip you're looking for is "192.168.55.100"
That's the ip address the phone uses to connect to the host pc.
If you'd like to connect to the phone, apparently its ip address will be "192.168.55.101"
For the emulator just use localhost or 127.0.0.1
This is from the old ActiveSync days, so I don't know how official it is or how likely it is to last, but for right now at least it worked on my phone.

Related

Remote.it and openVPN together

So this is a classic question that I’ve seen many times before...
I’m trying to connect to my home network when not at home using a raspberry pi.
I’m well aware that the way to go with this is to use a vpn server such as OpenVPN.
However, in order to connect to the vpn I would need to forward a port on my router... which I can’t do.
I’ve found remote.it which allows remote connection to a computer (pi) without port forwarding.
What I would like to know is how would I set about using the 2 together, I.e. connecting to remote.it which in turn connects me to my vpn server?
I'm sorry to be finding this question just now, but in case it's still useful to you or to anyone else, here's what you need to do:
Install remote.it
Set-up a remote.it connection to use the protocol (TCP/UDP) and port required by the VPN application
Make a remote.it connection/adding the service to your network (remoteit - Desktop application UI terminology)
Use this connection info (URL/port or localhost:port) with the VPN client
Send an e-mail to support#remote.it if you need help
I would recommend ZeroTier(https://www.zerotier.com/). It haves its own linux client , and you can connect to as many networks as you would like.
You can also configure IP address from the website.
There is also an Android an IOS app that is really simple to connect.

Debugging network connections on the iPad. Any tools or techniques?

I'm trying to get my iPad (3rd gen) to access a website on my workstation over an https connection (though I should perhaps mention I cannot connect to it over HTTP either). The aim is to have a working demo of two-way authentication with certificates.
I've installed the client cert on the iPad and a number of Windows and OSX machines on our network. But the iPad seems to be having trouble getting the IP from the local DNS server or perhaps hitting the DNS server at all. As there doesn't seem to be a Hosts file or any way of debugging the network side of the iPad I'm a bit stuck.
Does anyone have any hints/tips/tools that could make my life half-way bearable?
Unfortunately things like you mention aren't built in in iOS. I would have a look in the App Store and get an app to perform pings and do DNS lookups. Maybe NetTools could work for you?

How to set up http server on iPhone behind firewall

I want to develop an iPhone app with a simple IM feature. I am thinking about setting up an HTTP server on an iPhone. If the iPhone is using wifi and is behind a firewall, how can I make sure that other iPhone clients can connect to it?
It's not the firewall that will disturb the connection as much it is the NAT.
When you are connected through wireless router to connect the internet you are surfing via NAT. it means you dont really have an extenral IP but once you initiate connection the router will map your intenral IP to one of his externatl ports and for certain time window he will pass connections to you if he will get it to the right port.
That being said, there is no actual way of setting a server behind a NAT unless you can configure port forwarding in the router and internal static IP.
Hope i was clear enough, good luck
I do not really think that you need to get an HTPP server up and running on iPhone to make an application that can send and receive messages (IM). The idea of making one iPhone user to directly connect to one another does not seem right to me since the users will need to know IP addresses of one another to do that.
Interconnectivity between different users of the chat can be solved by making your application communicate via a dedicated TCP port. It is generally advisable to choose ports with a number higher than 1024 since those below are generally found on the list of so-called well-known ports and are used for Web (like port 80), FTP (port 21), SSH (22), DNS (53), etc., it will be the responsibility of the user to make sure the port used by your application is open on the firewall. In order to solve this problem you can actually use port 80 for communication if you find that the port you have selected is blocked. You can do this because you know that this port will not be blocked in most cases. Indeed Yahoo Messenger is reported to use this technique when the firewall blocks the port it uses for communication.
The port should be used by your application to connect to the Web-server that will actually store user credentials, perform authentication, message transmission, etc., and the server should reside on capable hardware to be able to support large number of simultaneous connections. I can suggest using either a VPS (like the one provided by Linode) or a cloud (like Amazon EC2, Google Application Engine, Rackspace).

iPhone - access XAMPP server (localhost) on my mac in the same network

I want to create an iPhone app which makes calls to a web service. For testing, I want to first create the API calls on my mac (server running XAMPP) and if it works fine there I want to port it to the actual server.
If my iPhone and mac are on the same network, can I access the web service using the IP address of my mac?
Thanks.
Any time someone answers with "why not," ignore the post. This just takes up space and adds absolutely no value...their post imitating their life.
Anyway, I access my laptop localhost (WAMP stack) from my iPod Touch by entering the IP address of my laptop on my Touch location bar. There is some configuration that needs to happen for this to work. I found what I needed at:
http://www.frihost.com/forums/vt-88381.html
Good Luck!
I can not speak about actual development, however I access intranet pages from a Ipod Touch all the time by either typing http ://ip or http://local_dns_name
As long as the iphone / ipod is on the network correctly (e.g. through standard wifi and not 3g/whatever) you should be able to access any and all local resources.
What I do:
Connected to the same network, I go in to the wireless settings and create a manual proxy that points to my machine. I use Charles proxy for testing a lot/seeing traffic, works like a charm and it lets me use my macbook hosts file so I don't need to do any funky listening rules in apache - just the same vhost settings I use on my machine already.
http://www.charlesproxy.com/documentation/faqs/using-charles-from-an-iphone/
Why not?
Have you tried it and have some problems?

Restrict the server access from LAN only

Recently we got a new server at the office purely for testing purposes. It is set up so that we can access it from any computer.
However today our ip got blocked from one of our other sites saying that our ip has been suspected of having a virus that sends spam emails. we learned this from the cbl http://cbl.abuseat.org/
So of course we turned the server off to stop this. The problem is the server must be on to continue developing our application and to access the database that is installed on it. Our normal admin is on vacation and is unreachable, and the rest of us are idiots(me included) in this area.
We believe that the best solution is to remove it from connecting to the internet but still access it on the lan. If that is a valid solution how would this be done or is there a better way? say blocking specified ports or whatever.
I assume that this server is behind a router? You should be able to block WAN connections to the server on the router and still leave it open to accepting LAN connection. Or you could restrict the IPs that can connect to the server to the development machines on the network.