use of jgnash.engine.attachment.NettyTransferHandler in project jgnash by ccavanaugh.
the class AttachmentTransferClient method connectToServer.
/**
* Starts the connection with the lock server.
*
* @param host remote host
* @param port connection port
* @param password connection password
* @return {@code true} if successful
*/
boolean connectToServer(final String host, final int port, final char[] password) {
boolean result = false;
// If a password has been specified, create an EncryptionManager
if (password != null && password.length > 0) {
encryptionManager = new EncryptionManager(password);
}
final Bootstrap bootstrap = new Bootstrap();
eventLoopGroup = new NioEventLoopGroup();
transferHandler = new NettyTransferHandler(tempDirectory, encryptionManager);
bootstrap.group(eventLoopGroup).channel(NioSocketChannel.class).handler(new Initializer()).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, ConnectionFactory.getConnectionTimeout() * 1000).option(ChannelOption.SO_KEEPALIVE, true);
try {
// Start the connection attempt.
channel = bootstrap.connect(host, port).sync().channel();
result = true;
logger.info("Connection made with File Transfer Server");
} catch (final InterruptedException e) {
logger.log(Level.SEVERE, "Failed to connect to the File Transfer Server", e);
disconnectFromServer();
}
return result;
}
Aggregations