use of java.net.Socket in project bigbluebutton by bigbluebutton.
the class SocketScreenVideoSender method connect.
/* BBB-DS */
public void connect(String host, String room, int width, int height) throws ConnectionException {
this.room = room;
this.width = width;
this.height = height;
try {
socket = new Socket(host, PORT);
outStream = new DataOutputStream(socket.getOutputStream());
sendHeaderEventAndRoom(CaptureEvents.CAPTURE_START.getEvent());
sendScreenCaptureInfo(width, height);
outStream.flush();
} catch (UnknownHostException e) {
e.printStackTrace();
throw new ConnectionException("UnknownHostException: " + host);
} catch (IOException e) {
e.printStackTrace();
throw new ConnectionException("IOException: " + host + ":" + PORT);
}
System.out.println("Starting capturedScreenSender ");
sendCapturedScreen = true;
capturedScreenSender = new Runnable() {
public void run() {
while (sendCapturedScreen) {
try {
//System.out.println("ScreenQueue size " + screenQ.size());
ScreenVideo newScreen = screenQ.take();
try {
sendCapturedScreen(newScreen);
} catch (ConnectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (InterruptedException e) {
System.out.println("InterruptedExeption while taking event.");
}
}
}
};
exec.execute(capturedScreenSender);
}
use of java.net.Socket in project musiccabinet by hakko.
the class JdbcDatabaseAdministrationDao method isRDBMSRunning.
/*
* Verify that a postgresql server is running.
*
* Try sending what pgAdmin would send when connecting to a postgresql server,
* and verify that we get an 'R' back as first character from the database
* ('R' = authentication request).
*
* Iff we get that, we decide that we have a postgresql server at hand.
*
* TODO : it would be good to check version of postgresql server, but that isn't
* officially available until we have a user account. Checking it indirectly by
* looking at line numbers in error message (those change between postgresql
* releases) seems too ugly/error prone.
*/
@Override
public boolean isRDBMSRunning() {
boolean running = false;
try {
Socket socket = new Socket(host, port);
PrintWriter pw = new PrintWriter(socket.getOutputStream());
pw.print(new char[] { (char) 0, (char) 0, (char) 0, (char) 42, (char) 0, (char) 3, (char) 0, (char) 0, 'u', 's', 'e', 'r', (char) 0, 'p', 'o', 's', 't', 'g', 'r', 'e', 's', (char) 0, 'd', 'a', 't', 'a', 'b', 'a', 's', 'e', (char) 0, 't', 'e', 'm', 'p', 'l', 'a', 't', 'e', '1', (char) 0, (char) 0 });
pw.flush();
InputStreamReader isr = new InputStreamReader(socket.getInputStream());
char response = (char) isr.read();
running = true;
if (response != 'R') {
LOG.warn("Expected Postgresql server to return R, got " + response + ".");
}
socket.close();
} catch (IOException e) {
LOG.warn("Couldn't connect to Postgres service!", e);
// expected if database is down, or we've connected to something that's not postgre
}
return running;
}
use of java.net.Socket in project hazelcast by hazelcast.
the class ClientConnectionManagerImpl method createSocketConnection.
protected ClientConnection createSocketConnection(final Address address) throws IOException {
if (!alive) {
throw new HazelcastException("ConnectionManager is not active!");
}
SocketChannel socketChannel = null;
try {
socketChannel = SocketChannel.open();
Socket socket = socketChannel.socket();
socket.setKeepAlive(socketOptions.isKeepAlive());
socket.setTcpNoDelay(socketOptions.isTcpNoDelay());
socket.setReuseAddress(socketOptions.isReuseAddress());
if (socketOptions.getLingerSeconds() > 0) {
socket.setSoLinger(true, socketOptions.getLingerSeconds());
}
int bufferSize = getBufferSize();
socket.setSendBufferSize(bufferSize);
socket.setReceiveBufferSize(bufferSize);
InetSocketAddress inetSocketAddress = address.getInetSocketAddress();
socketChannel.socket().connect(inetSocketAddress, connectionTimeout);
SocketChannelWrapper socketChannelWrapper = socketChannelWrapperFactory.wrapSocketChannel(socketChannel, true);
final ClientConnection clientConnection = new ClientConnection(client, ioThreadingModel, connectionIdGen.incrementAndGet(), socketChannelWrapper);
socketChannel.configureBlocking(true);
if (socketInterceptor != null) {
socketInterceptor.onConnect(socket);
}
socketChannel.configureBlocking(ioThreadingModel.isBlocking());
socket.setSoTimeout(0);
clientConnection.start();
return clientConnection;
} catch (Exception e) {
if (socketChannel != null) {
socketChannel.close();
}
throw ExceptionUtil.rethrow(e, IOException.class);
}
}
use of java.net.Socket in project gradle by gradle.
the class Snarl method send.
private void send(InetAddress host, final String title, final String message) {
Socket socket = null;
try {
try {
socket = new Socket(host, 9887);
} catch (ConnectException e) {
// Snarl is not running
throw new AnnouncerUnavailableException("Snarl is not running on host " + String.valueOf(host) + ".", e);
}
PrintWriter printWriter = null;
try {
final OutputStream outputStream = socket.getOutputStream();
printWriter = new PrintWriter(outputStream, true);
printWriter.println(formatMessage(title, message));
} catch (IOException e) {
throw new UncheckedIOException(e);
} finally {
IOUtils.closeQuietly(printWriter);
}
} catch (IOException ioException) {
throw new UncheckedIOException(ioException);
} finally {
IOUtils.closeQuietly(socket);
}
}
use of java.net.Socket in project hazelcast by hazelcast.
the class TcpIpConnection method toString.
@Override
public String toString() {
Socket socket = socketChannel.socket();
SocketAddress localSocketAddress = socket != null ? socket.getLocalSocketAddress() : null;
SocketAddress remoteSocketAddress = socket != null ? socket.getRemoteSocketAddress() : null;
return "Connection[id=" + connectionId + ", " + localSocketAddress + "->" + remoteSocketAddress + ", endpoint=" + endPoint + ", alive=" + alive + ", type=" + type + "]";
}
Aggregations