标签: connection

当URL启动时,为什么会出现"java.net.ConnectException:Connection timed out"异常?

ConnectException: Connection timed out从代码中获得了一些频率.我试图点击的网址已经启动.相同的代码适用于某些用户,但不适用于其他用户.似乎一旦一个用户开始获得此异常,他们就会继续获得异常.

这是堆栈跟踪:

java.net.ConnectException: Connection timed out
Caused by: java.net.ConnectException: Connection timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.Socket.connect(Socket.java:516)
    at java.net.Socket.connect(Socket.java:466)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:214)
    at sun.net.www.http.HttpClient.New(HttpClient.java:287)
    at sun.net.www.http.HttpClient.New(HttpClient.java:299)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:796)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:748)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:673)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:840)
Run Code Online (Sandbox Code Playgroud)

以下是我的代码中的代码段:

URLConnection urlConnection = null;
OutputStream outputStream = null;
OutputStreamWriter outputStreamWriter = null;
InputStream inputStream = null;

try {
    URL url = new URL(urlBase);
    urlConnection = url.openConnection();
    urlConnection.setDoOutput(true);

    outputStream = …
Run Code Online (Sandbox Code Playgroud)

java connection urlconnection connectexception

81
推荐指数
5
解决办法
41万
查看次数

Python [Errno 98]地址已在使用中

在我的Python套接字程序中,我有时需要用它来中断它Ctrl-C.当我这样做时,它会使用关闭连接socket.close().

但是,当我尝试重新打开它时,我必须等待一段时间才能再次连接.如何正确关闭套接字?或者这是打算?

python sockets connection errno

80
推荐指数
8
解决办法
11万
查看次数

如何创建bash脚本来检查SSH连接?

我正在创建一个bash脚本,该脚本将登录到远程计算机并创建私钥和公钥.

我的问题是远程机器不是很可靠,而且它们并不总是正常运行.我需要一个bash脚本来检查SSH连接是否已启动.在实际创建密钥以供将来使用之前.

connection ssh bash

78
推荐指数
6
解决办法
14万
查看次数

在Java中什么时候URL连接关闭?

什么时候java放弃了到URL的连接?我没有在URL或URLConnection上看到close()方法,所以它会在请求完成后立即释放连接吗?我主要是想在异常处理程序中查看是否需要进行任何清理.

try {
  URL url = new URL("http://foo.bar");
  URLConnection conn = url.openConnection();
  // use the connection
}
catch (Exception e) {
  // any clean up here?
}
Run Code Online (Sandbox Code Playgroud)

java connection url exception

74
推荐指数
2
解决办法
6万
查看次数

立即检测客户端与服务器套接字的断开连接

如何检测客户端是否与服务器断开连接?

我有下面的代码在我的AcceptCallBack方法

static Socket handler = null;
public static void AcceptCallback(IAsyncResult ar)
{
  //Accept incoming connection
  Socket listener = (Socket)ar.AsyncState;
  handler = listener.EndAccept(ar);
}
Run Code Online (Sandbox Code Playgroud)

我需要找到一种方法来尽快发现客户端已从handlerSocket 断开连接.

我试过了:

  1. handler.Available;
  2. handler.Send(new byte[1], 0, SocketFlags.None);
  3. handler.Receive(new byte[1], 0, SocketFlags.None);

当您连接到服务器并且想要检测服务器何时断开连接但是当您是服务器并且想要检测客户端断开连接时它们不起作用时,上述方法会起作用.

任何帮助将不胜感激.

.net c# sockets connection tcp

72
推荐指数
4
解决办法
14万
查看次数

如何使用node.js连接mongodb(并进行身份验证)?

如何使用node.js连接到mongodb?

我有node-mongodb-native驱动程序.

显然有0个文档.

这是这样的吗?

var mongo = require('mongodb/lib/mongodb'); 
var Db= new mongo.Db( dbname, new mongo.Server( 'mongolab.com', 27017, {}), {}); 
Run Code Online (Sandbox Code Playgroud)

我在哪里输入用户名和密码?

另外我如何插入东西?

谢谢.

javascript authentication connection mongodb node.js

71
推荐指数
5
解决办法
10万
查看次数

HttpClient 4.0.1 - 如何释放连接?

我对一堆URL进行循环,对于每一个我正在执行以下操作的URL:

private String doQuery(String url) {

  HttpGet httpGet = new HttpGet(url);
  setDefaultHeaders(httpGet); // static method
  HttpResponse response = httpClient.execute(httpGet);   // httpClient instantiated in constructor

  int rc = response.getStatusLine().getStatusCode();

  if (rc != 200) {
    // some stuff...
    return;
  }

  HttpEntity entity = response.getEntity();

  if (entity == null) {
    // some stuff...
    return;
  }

  // process the entity, get input stream etc

}
Run Code Online (Sandbox Code Playgroud)

第一个查询没问题,第二个查询抛出此异常:

线程"main"中的异常java.lang.IllegalStateException:无效使用SingleClientConnManager:仍然分配了连接.确保在分配另一个连接之前释放连接.在org.apache.http.impl.conn.SingleClientConnManager.getConnection(SingleClientConnManager.java:199)org.apache.http.impl.conn.SingleClientConnManager $ 1.getConnection(SingleClientConnManager.java:173)......

这只是一个简单的单线程应用程序.我该如何发布此连接?

java connection apache-httpclient-4.x

70
推荐指数
6
解决办法
13万
查看次数

无法使用旧身份验证连接到MySQL 4.1+

我正在尝试连接到http://bluesql.net上的mySQL数据库,但是当我尝试连接时,它会出现此错误:

Connect Error (2000) mysqlnd cannot connect to MySQL 4.1+ using old authentication
Run Code Online (Sandbox Code Playgroud)

我研究了这个,它与MySQL 4.1之前使用的一些旧密码方案有关.较新的版本可以选择使用旧密码,我读过这些密码可能会导致此问题.

我正在运行php 5.3,并连接mySQLi(新的mysqli(...)).我希望我能在代码中做些什么来连接到bluesql.net上的数据库 - 显然我不控制他们的数据库是如何设置的.降级php版本不是一个选项.

有人有主意吗?

php mysql authentication connection

69
推荐指数
4
解决办法
14万
查看次数

Hibernate慢慢收购Postgres连接

我很难调试这个问题.每当我尝试与postgres建立连接时,都需要一分钟.建立连接后,一切都很好.我已经尝试禁用所有映射而不加载任何映射,但仍然需要很长时间才能获取.我也试过禁用验证,没有区别.当我使用简单的简单JDBC连接时,它就是瞬间的.Hibernate正在做一些花费大量时间的事情,我似乎无法缩小范围.任何输入都非常感谢!

Postgres驱动程序:

postgresql-9.1-901.jdbc4.jar
Run Code Online (Sandbox Code Playgroud)

配置设置:

<hibernate-configuration>
    <session-factory>
    <!-- properties -->
        <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="connection.driver_class">org.postgresql.Driver</property>

        <property name="connection.url">jdbc:postgresql://xxxx.com:5432/xxxxx</property>
        <property name="connection.username">xxxxxxx</property>
        <property name="connection.password">xxxxxxx</property>

    </session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)

代码中的其他设置:

    config.setProperty("hibernate.hbm2ddl.auto", hbm2ddlMode);
    //config.setProperty("hibernate.cache.use_query_cache", "true");
    config.setProperty("hibernate.cache.use_second_level_cache", "true");
    //config.setProperty("hibernate.cache.region.factory_class", "net.sf.ehcache.hibernate.EhCacheRegionFactory");
    config.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.EhCacheProvider");
    //config.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.NoCacheProvider");
    config.setProperty("hibernate.jdbc.fetch_size", "100");
    config.setProperty("hibernate.jdbc.batch_size", "30");
    config.setProperty("hibernate.jdbc.use_scrollable_resultset", "true");
    config.setProperty("hibernate.connection.provider_class", "org.hibernate.connection.C3P0ConnectionProvider");

    config.setProperty("hibernate.c3p0.acquire_increment", "1");
    config.setProperty("hibernate.c3p0.idle_test_period", "0");
    config.setProperty("hibernate.c3p0.min_size", "1");
    config.setProperty("hibernate.c3p0.max_size", "2");
    config.setProperty("hibernate.c3p0.timeout", "0");
    config.setProperty("javax.persistence.validation.mode", "none");
Run Code Online (Sandbox Code Playgroud)

这是发生延迟的代码段:

private SessionFactory buildSessionFactory() throws Exception {
        ServiceRegistry serviceRegistry  = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();

            //Building session takes a whole minute without mappings!!!
        sessionFactory = config.buildSessionFactory(serviceRegistry);

        validateConnection();

        return sessionFactory; …
Run Code Online (Sandbox Code Playgroud)

java postgresql connection hibernate

60
推荐指数
3
解决办法
3万
查看次数

如何在C#中检查套接字是否已连接/断开?

如果其他主机在断开连接时没有向您发送数据包(例如因为它不正常地断开连接),如何检查网络套接字(System.Net.Sockets.Socket)是否仍然连接?

c# sockets connection

59
推荐指数
6
解决办法
11万
查看次数