Xamarin.Forms app TcpClient Error on Connect with "No route to host" exception - xamarin.forms

I am having very strange issue. I have 2 application, one is just my proof of concept, the other one is my real app. Both are Xamarin.Forms applications supporting Android, iOS, and UWP.
Both of these apps use TcpClient to connect to my IP and Port# on another machine. But here is what happens:
My proof-of-concept app works fine, it can send and receive data
to/from that IP/Port#
I also use app TerminalEmulator on Android and Ping on iOS which allow you to ping the IP address. Both devices are able to ping the IP meaning the IP is visible to the devices
But, if I try to connect from my real app on same devices, I get "No route to host" exception
How come my POC app can connect, I can ping the host from my Android/IOS device, but I cannot connect from my real app and get this error:
This is how I try to connect
public override async Task<IList<RoomGuestModel>> GetRoomGuestAsync(string roomNumber)
{
using (TcpClient client = new TcpClient())
{
try
{
client.Connect(_tcpConnection.Address, _tcpConnection.Port);
}
catch(Exception ex)
{
}
...
...
// use NetworkStream to write message and read message
await myStream.WriteAsync(...);
...
await myStream.ReadAsync(...);

The problem was that I was using wrong IP address, once I provided correct address, I was able to connect

Related

Socket.Connect to SMTP to verify email always returns with smtp connection timeout

I've written a tool that validates emails, mostly copied from various examples on the subject around on the internet (user Don Worthley compiled a decent collection of code samples here https://delicious.com/dworthley/email.validation). Unfortunately after creating the socket and the IPEndPoint from the email to verify's hostname IP and port, my code always fails to connect to the socket due to timeout.
Here is the pertinent code (fails at s.Connect(endPt) due to timeout):
private bool smtpCheckEmail(string email)
{
try
{
string[] host = (email.Split('#'));
string hostname = host[1];
IPHostEntry IPhst = Dns.GetHostEntry(hostname);
IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
using (Socket s = new Socket(endPt.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
{
try
{
s.Connect(endPt);
}
catch
{
s.Close();
return false;
}
From my research others have reported success with similar code so it might be an issue with my server host. The MVC project is on a GoDaddy VPS with Windows 7 and standard firewall/MSSE as protection (I've tested with both disabled with same timeout result).
I've verified I can telnet to my own host and run through the various HELO, Mail from etc commands but it also times out if I try to connect to smtp for other hosts.
Maybe it's an ISP issue?
I've also tried installing EmailVerify for .NET trial but run into the same problem where any validation at or above SMTP check times out.
Would be great to get some suggestions of what might be the problem and how to troubleshoot it.
Edit: After doing some comparison testing with one of my Azure VPS it looks like it is likely to be server related, "telnet 74.125.206.108 smtp" (gmail's smtp host IP) through command line connects on the Azure box but not on the GoDaddy one my project is on.
I also notice that when my code pulls the IP from the host name (Dns.GetHostEntry(hostname)), in this gmail example it returns 216.58.216.37 which matches what I get if a run nslookup in cmd for gmail.com, however the IP for smtp that I can telnet to is for gmail is 74.125.206.108 which matches the nslookup record for smtp.gmail.com. Could my code be grabbing the wrong IP addresses in many cases here?
Turned out to be a limitation of GoDaddy VPS. Transferred code to an Azure hosted project and it worked great.

How to find if two distinct accounts are being accessed from same computer but using different browser?

I couldn't track a machine using ip-address because I usually get proxy server address
public static String GetIP()
{
String ip =
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(ip))
{
ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
return ip;
}
Are there any other ways to track a machine correctly?
Reading ip-address is the only way But with that also you can't trace exactly due to Network address translators,Proxy servers and VPN servers etc.
You have to understand this its privacy issue
Even in iOS also they have forbidden to read UDID right from iOS 7 as it infringes users privacy
Hope this solves your problem

SignalR self hosting with owin

I want to create an signalr app that will be self hosted using Owin, so to start off i tried to run the sample that is on https://github.com/SignalR/SignalR/wiki/Self-host. But when i run the application and then navigate to /signar/hubs i get a 500 Server error. I get the same exception when i try to connect from my client app.
Do i need to add something else apart from what is in the sample code? or does anyone know of a good tutorial?
Things to check if trying to access from an external connection:
Are you hosting the server on all addresses or just localhost?
// use http://*:8080 to bind to all addresses.
string url = "http://localhost:8080";
Make sure to run app as administrator.
Also, is the Windows firewall blocking the port you are using? I had to add an exception to allow incoming TCP connections on that port.

JavaDB(Derby) - Connection refused using Network Server Controller in LAN

I'm new to java networking. My scenario here is 2 client computers are connecting to a server hosted in LAN. So I use NetworkServerControl API to start the host:
private static void startServer(){
try{
NetworkServerControl nsc = new NetworkServerControl(InetAddress.getByName("localhost"), 1527);
nsc.start(null);
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Start network error : " + e.getMessage());
}
My questions are:
1) Is localhost accessible by computers in LAN?
- If yes, I tried to use ij to connect derby database in the server but it wrote connection refused. Anything I missed out?
ij: CONNECT 'jdbc:derby://localhost:1527/c:/app_db/' user 'xxx' password 'xxx';
- If no, what is the common approach should be used? Please guide me the right track.
Thanks.
To access your Derby database from other machines on the network, you need to change "localhost" to a different value. You can give the DNS name of your machine, or the public IP address of your machine.
Note that you have to make this change both on the Derby server and on each of the client URLs.
You should be able to use netstat -a to confirm the effects of your changes on the server.

Is there a way to access the remote IP of a RTMFP p2p stream?

I'm writing a communication system, using Actionscript 3 and C#. Flash is used to communicate with RTMP server and stream video and audio using RTMFP p2p, but the actual client logic is handled in C#.
What I want to be able to do, is allow users to share files between each other also using a direct p2p connection.
I have got the RTMFP connection working but I need to access the IP address of the remote user so I can initiate a connection to send or receive files.
I looked at the Adobe docs but I can't see anything except how to access the farID.
Is there a way to get the IP of a RTMFP stream?
I think you can't get the IP address through RTMFP connection, but you could use a shared object to record client IPs as a workaround:
application.onAppStart = function() {
application.so = SharedObject.get('my_shared_obj');
}
application.onConnect = function(clientObj, username, password) {
// TODO check username and password
application.so.setProperty(clientObj.farID, clientObj.ip);
}
application.onDisconnect = function(clientObj) {
application.so.setProperty(clientObj.farID, null);
}

Resources