Search in sources :

Example 1 with NettyTransferHandler

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;
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) EncryptionManager(jgnash.util.EncryptionManager) ChannelInitializer(io.netty.channel.ChannelInitializer) Bootstrap(io.netty.bootstrap.Bootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) NettyTransferHandler(jgnash.engine.attachment.NettyTransferHandler)

Aggregations

Bootstrap (io.netty.bootstrap.Bootstrap)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 NettyTransferHandler (jgnash.engine.attachment.NettyTransferHandler)1 EncryptionManager (jgnash.util.EncryptionManager)1