我写了一段java代码如下
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();;
}
在这里,我向接受 ip 作为参数并发送国家和地区作为响应的 Web 服务发送获取请求。
这几天工作正常,但后来它开始抛出“本地异常失败:java.net.SocketException:没有可用的缓冲区空间(达到最大连接数?)”。 我搜索了谷歌,其中大部分都指定断开 http 对象。我也做过,但我会遇到同样的错误。任何人都可以帮助我吗
最佳答案
这很可能是服务器端问题,尤其是。由于端口号限制,它在 Windows Server 2003 上非常流行。您的服务器端详细信息是什么?
引用其他答案,no buffer space available
关于java - 因本地异常 : java.net.SocketException : No buffer space available (maximum connections reached? 失败):,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31136359/