Santhosh

Santhosh

  • NA
  • 300
  • 140.7k

System.Net.Sockets.SocketException: Connection timed out

Nov 18 2016 2:40 AM
hi,
 
I was trying to find a Current mobile location,It's working.
After that POST the data in my local server. when I post the data in the server it will display this error.
 
  "System.Net.Sockets.SocketException: Connection timed out" 
 
 
async void AddressButton_OnClick(object sender, EventArgs eventArgs)
{
if (currentLocation == null)
{
addressText.Text = "Can't determine the current address. Try again in a few minutes.";
return;
}
Address address = await ReverseGeocodeCurrentLocation();
DisplayAddress(address);
#region HttpResponce
try
{
var request = HttpWebRequest.Create(string.Format(@"http://192.168.1.88:53706/api/Getlocation", ""));
request.ContentType = "application/json";
request.Method = "POST";
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) //Error display this line
{
if (response.StatusCode != HttpStatusCode.OK)
System.Console.Out.WriteLine("Error fetching data. Server returned status code: {0}", response.StatusCode);
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
var content = reader.ReadToEnd();
if (string.IsNullOrWhiteSpace(content))
{
System.Console.Out.WriteLine("Response contained empty body...");
}
else
{
System.Console.Out.WriteLine("Response Body: \r\n {0}", addressText);
}
}
}
}
catch (System.Exception ex) when (ex is System.Net.Sockets.SocketException ||
ex is InvalidOperationException )
{
System.Console.Out.
WriteLine("task has been cancelled.");
System.Console.Out.WriteLine(ex.Message);
}
#endregion
}
 
how to solve Timeout issue ...? 
 

Answers (1)