I have written a java code as below
String fulldetails ="";
String line="";
String result="";
URL url;
HttpURLConnection conn;
BufferedReader rd;
String country="";
String region="";
String city="";
String zipcode="";
try
{
String ip = "xxx.xxx.xx.x";
url = new URL("http://xxx.xx.xxx.x:2298/api/sample?ip="+ip);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = rd.readLine()) != null)
{
result += line;
}
System.out.println(result);
rd.close();
result = result.substring(1, result.length()-1);
JSONObject json_object = new JSONObject(result);
country = (String) json_object.get("Country");
System.out.println(country);
region = (String) json_object.get("Region");
System.out.println(region);
city = (String) json_object.get("City");
System.out.println(city);
zipcode = (String) json_object.get("ZipCode");
System.out.println(zipcode);
fulldetails = "Country:"+country+",Region:"+region+",City:"+city+","+"ZipCode:"+zipcode;
System.out.println(fulldetails);
conn.disconnect();
}
catch(Exception exception)
{
exception.printStackTrace();;
}
Here I am sending a get request to a web services which accepts ip as parameter and sends country and its region as its response.
This works fine for few days but later it begin to throw "Failed on local exception: java.net.SocketException: No buffer space available (maximum connections reached?)". I have searched google and most of it specifies to disconnect the http object. I had also done it but I ma getting the same error. Can any one help me in thsi