use of java.net.Socket in project fqrouter by fqrouter.
the class DNSConnection method open.
/**
* NOTE: old connection should be closed. server must be != null. If
* server is down or unreachable then NoRouteToHostException
* (subclass of SocketException) is thrown. If connection is
* remotely refused then ConnectException (subclass of
* SocketException) is thrown. If SecurityException is caught then
* SocketException is thrown. Must be synchronized outside.
**
* @since 2.2
*/
public void open(InetAddress server) throws NullPointerException, IOException {
server.hashCode();
try {
Socket socket = new Socket(server, PORT);
BufferedInputStream in = new BufferedInputStream(socket.getInputStream(), DNSMsgHeader.UDP_PACKET_LEN);
this.out = socket.getOutputStream();
this.in = in;
this.socket = socket;
} catch (SecurityException e) {
throw new SocketException("SecurityException: connect(" + server.getHostAddress() + ")");
}
this.msgBytes = null;
}
use of java.net.Socket in project XobotOS by xamarin.
the class FtpURLConnection method connectInternal.
private void connectInternal() throws IOException {
int port = url.getPort();
int connectTimeout = getConnectTimeout();
if (port <= 0) {
port = FTP_PORT;
}
if (currentProxy == null || Proxy.Type.HTTP == currentProxy.type()) {
controlSocket = new Socket();
} else {
controlSocket = new Socket(currentProxy);
}
InetSocketAddress addr = new InetSocketAddress(hostName, port);
controlSocket.connect(addr, connectTimeout);
connected = true;
ctrlOutput = controlSocket.getOutputStream();
ctrlInput = controlSocket.getInputStream();
login();
setType();
if (!getDoInput()) {
cd();
}
try {
acceptSocket = new ServerSocket(0);
dataPort = acceptSocket.getLocalPort();
/* Cannot set REUSEADDR so we need to send a PORT command */
port();
if (connectTimeout == 0) {
// set timeout rather than zero as before
connectTimeout = 3000;
}
acceptSocket.setSoTimeout(getConnectTimeout());
if (getDoInput()) {
getFile();
} else {
sendFile();
}
dataSocket = acceptSocket.accept();
dataSocket.setSoTimeout(getReadTimeout());
acceptSocket.close();
} catch (InterruptedIOException e) {
throw new IOException("Could not establish data connection");
}
if (getDoInput()) {
inputStream = new FtpURLInputStream(new BufferedInputStream(dataSocket.getInputStream()), controlSocket);
}
}
use of java.net.Socket in project zaproxy by zaproxy.
the class DecoratedSocketsSslSocketFactory method createSocket.
@Override
public Socket createSocket(final Socket s, final String host, final int port, final boolean autoClose) throws IOException {
Socket socket = delegate.createSocket(s, host, port, autoClose);
decorate((SSLSocket) socket);
return socket;
}
use of java.net.Socket in project zaproxy by zaproxy.
the class DecoratedSocketsSslSocketFactory method createSocket.
@Override
public Socket createSocket(final String host, final int port, final InetAddress localHost, final int localPort) throws IOException, UnknownHostException {
Socket socket = delegate.createSocket(host, port, localHost, localPort);
decorate((SSLSocket) socket);
return socket;
}
use of java.net.Socket in project zaproxy by zaproxy.
the class RelaxedX509TrustManager method createSocket.
/**
* Attempts to get a new socket connection to the given host within the
* given time limit.
*
* @param host
* the host name/IP
* @param port
* the port on the host
* @param localAddress
* the local host name/IP to bind the socket to
* @param localPort
* the port on the local machine
* @param params
* {@link HttpConnectionParams Http connection parameters}
*
* @return Socket a new socket
*
* @throws IOException
* if an I/O error occurs while creating the socket
* @throws UnknownHostException
* if the IP address of the host cannot be determined
* @throws ConnectTimeoutException
*/
@Override
public Socket createSocket(final String host, final int port, final InetAddress localAddress, final int localPort, final HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
if (params == null) {
throw new IllegalArgumentException("Parameters may not be null");
}
int timeout = params.getConnectionTimeout();
if (timeout == 0) {
InetAddress hostAddress = getCachedMisconfiguredHost(host, port);
if (hostAddress != null) {
return clientSSLSockFactory.createSocket(hostAddress, port, localAddress, localPort);
}
try {
SSLSocket sslSocket = (SSLSocket) clientSSLSockFactory.createSocket(host, port, localAddress, localPort);
sslSocket.startHandshake();
return sslSocket;
} catch (SSLException e) {
if (!e.getMessage().contains(CONTENTS_UNRECOGNIZED_NAME_EXCEPTION)) {
throw e;
}
hostAddress = InetAddress.getByName(host);
cacheMisconfiguredHost(host, port, hostAddress);
return clientSSLSockFactory.createSocket(hostAddress, port, localAddress, localPort);
}
}
Socket socket = clientSSLSockFactory.createSocket();
SocketAddress localAddr = new InetSocketAddress(localAddress, localPort);
socket.bind(localAddr);
SocketAddress remoteAddr = new InetSocketAddress(host, port);
socket.connect(remoteAddr, timeout);
return socket;
}
Aggregations