-
Notifications
You must be signed in to change notification settings - Fork 897
Expand file tree
/
Copy pathConnectionFactory.java
More file actions
29 lines (26 loc) · 965 Bytes
/
ConnectionFactory.java
File metadata and controls
29 lines (26 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package org.csource.fastdfs.pool;
import org.csource.common.MyException;
import org.csource.fastdfs.ClientGlobal;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
public class ConnectionFactory {
/**
* create from InetSocketAddress
*
* @param socketAddress
* @return
* @throws IOException
*/
public static Connection create(InetSocketAddress socketAddress) throws IOException {
try {
Socket sock = new Socket();
sock.setReuseAddress(true);
sock.setSoTimeout(ClientGlobal.g_network_timeout);
sock.connect(socketAddress, ClientGlobal.g_connect_timeout);
return new Connection(sock, socketAddress);
} catch (Exception e) {
throw new IOException("connect to server " + socketAddress.getAddress().getHostAddress() + ":" + socketAddress.getPort() + " fail, emsg:" + e.getMessage(), e);
}
}
}