use of java.net.ServerSocket in project gitblit by gitblit.
the class FanoutSocketService method connect.
@Override
protected boolean connect() {
if (serviceSocket == null) {
try {
serviceSocket = new ServerSocket();
serviceSocket.setReuseAddress(true);
serviceSocket.setSoTimeout(serviceTimeout);
serviceSocket.bind(host == null ? new InetSocketAddress(port) : new InetSocketAddress(host, port));
logger.info(MessageFormat.format("{0} is ready on {1}:{2,number,0}", name, host == null ? "0.0.0.0" : host, serviceSocket.getLocalPort()));
} catch (IOException e) {
logger.error(MessageFormat.format("failed to open {0} on {1}:{2,number,0}", name, host == null ? "0.0.0.0" : host, port), e);
return false;
}
}
return true;
}
use of java.net.ServerSocket in project fqrouter by fqrouter.
the class DNSConnection method openIncoming.
/**
* NOTE: old connection should be closed. Wait for any incoming
* connection and accept it. If listening is not active or if
* SecurityException is caught then SocketException is thrown. If
* waiting fails then InterruptedIOException is thrown. Must be
* synchronized outside.
**
* @since 3.0
*/
public void openIncoming() throws IOException {
ServerSocket curListener;
if ((curListener = listener) != null) {
try {
Socket socket = curListener.accept();
BufferedInputStream in = new BufferedInputStream(socket.getInputStream(), DNSMsgHeader.UDP_PACKET_LEN);
this.out = socket.getOutputStream();
this.in = in;
this.msgBytes = null;
this.socket = socket;
return;
} catch (SecurityException e) {
}
}
throw new SocketException(curListener == null ? "Not listening" : "SecurityException: accept()");
}
use of java.net.ServerSocket 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.ServerSocket in project zaproxy by zaproxy.
the class ProxyServerSSL method createServerSocket.
@Override
protected ServerSocket createServerSocket(String ip, int port) throws UnknownHostException, IOException {
// ZAP: added the possibility to bound to all interfaces (using null as InetAddress)
// when the ip is null or an empty string
InetAddress addr = null;
if ((ip != null) && !ip.isEmpty()) {
addr = InetAddress.getByName(ip);
}
//ServerSocket socket = ssl.listen(port, 300, InetAddress.getByName(getProxyParam().getProxyIp()));
ServerSocket socket = ssl.listen(port, 300, addr);
return socket;
}
use of java.net.ServerSocket in project hazelcast by hazelcast.
the class ManagementCenterServiceIntegrationTest method availablePort.
private int availablePort() throws IOException {
while (true) {
int port = (int) (65536 * Math.random());
try {
ServerSocket socket = new ServerSocket(port);
socket.close();
return port;
} catch (Exception ignore) {
// try next port
}
}
}
Aggregations