use of jnr.unixsocket.UnixSocketAddress in project jetty.project by eclipse.
the class UnixSocketClient method main.
public static void main(String[] args) throws Exception {
java.io.File path = new java.io.File("/tmp/jetty.sock");
String data = "GET / HTTP/1.1\r\nHost: unixsock\r\n\r\n";
UnixSocketAddress address = new UnixSocketAddress(path);
UnixSocketChannel channel = UnixSocketChannel.open(address);
System.out.println("connected to " + channel.getRemoteSocketAddress());
PrintWriter w = new PrintWriter(Channels.newOutputStream(channel));
InputStreamReader r = new InputStreamReader(Channels.newInputStream(channel));
while (true) {
w.print(data);
w.flush();
CharBuffer result = CharBuffer.allocate(4096);
r.read(result);
result.flip();
System.out.println("read from server: " + result.toString());
Thread.sleep(1000);
}
}
use of jnr.unixsocket.UnixSocketAddress in project linuxtools by eclipse.
the class DefaultUnixConnectionSettingsProvider method getConnectionSettings.
@Override
public List<IDockerConnectionSettings> getConnectionSettings() {
// $NON-NLS-1$
final File unixSocketFile = new File("/var/run/docker.sock");
if (unixSocketFile.exists() && unixSocketFile.canRead() && unixSocketFile.canWrite()) {
final UnixSocketAddress address = new UnixSocketAddress(unixSocketFile);
try (final UnixSocketChannel channel = UnixSocketChannel.open(address)) {
// assume socket works
final UnixSocketConnectionSettings socket = new UnixSocketConnectionSettings(DefaultDockerConnectionSettingsFinder.Defaults.DEFAULT_UNIX_SOCKET_PATH);
socket.setName(socket.getPath());
return Arrays.asList(socket);
} catch (IOException e) {
// do nothing, just assume socket did not work.
}
}
return Collections.emptyList();
}
use of jnr.unixsocket.UnixSocketAddress in project jetty.project by eclipse.
the class UnixSocketConnector method open.
public void open() throws IOException {
if (_acceptChannel == null) {
UnixServerSocketChannel serverChannel = UnixServerSocketChannel.open();
SocketAddress bindAddress = new UnixSocketAddress(new File(_unixSocket));
serverChannel.socket().bind(bindAddress, getAcceptQueueSize());
serverChannel.configureBlocking(getAcceptors() > 0);
addBean(serverChannel);
LOG.debug("opened {}", serverChannel);
_acceptChannel = serverChannel;
}
}
Aggregations