thufir

new foo

Jul 26th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. package net.bounceme.dur.client.netty;
  2.  
  3. import io.netty.bootstrap.Bootstrap;
  4. import io.netty.channel.Channel;
  5. import io.netty.channel.ChannelOption;
  6. import io.netty.channel.EventLoopGroup;
  7. import io.netty.channel.nio.NioEventLoopGroup;
  8. import io.netty.channel.socket.nio.NioDatagramChannel;
  9. import java.util.logging.Logger;
  10. import javax.net.ssl.SSLException;
  11. import net.bounceme.dur.client.jdbc.Title;
  12.  
  13. /**
  14.  * Modification of {@link EchoClient} which utilizes Java object serialization.
  15.  */
  16. public final class Client {
  17.  
  18.     private static final Logger log = Logger.getLogger(Client.class.getName());
  19.     static final int SIZE = Integer.parseInt(System.getProperty("size", "256"));
  20.  
  21.     public Client() {
  22.     }
  23.  
  24.     public void init() throws InterruptedException, SSLException {
  25.         MyProps p = new MyProps();
  26.         String host = p.getHost();
  27.         int port = p.getServerPort();
  28.         startClient(host, port);
  29.     }
  30.  
  31.     private void startClient(final String host, final int port) throws SSLException, InterruptedException {
  32.         EventLoopGroup group = new NioEventLoopGroup();
  33.         try {
  34.             Bootstrap b = new Bootstrap();
  35.             b.group(group)
  36.                     .channel(NioDatagramChannel.class)
  37.                     .option(ChannelOption.SO_BROADCAST, true)
  38.                     .handler(new ClientHandler());
  39.             Channel ch = b.bind(0).sync().channel();
  40.             ch.writeAndFlush(new Title()).sync();
  41.         } finally {
  42.             group.shutdownGracefully();
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment