Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.bounceme.dur.client.netty;
- import io.netty.bootstrap.Bootstrap;
- import io.netty.buffer.Unpooled;
- import io.netty.channel.Channel;
- import io.netty.channel.ChannelOption;
- import io.netty.channel.EventLoopGroup;
- import io.netty.channel.nio.NioEventLoopGroup;
- import io.netty.channel.socket.DatagramPacket;
- import io.netty.channel.socket.nio.NioDatagramChannel;
- import static io.netty.handler.codec.rtsp.RtspHeaders.Values.PORT;
- import io.netty.util.CharsetUtil;
- import java.net.InetSocketAddress;
- import java.util.logging.Logger;
- import javax.net.ssl.SSLException;
- /**
- * Modification of {@link EchoClient} which utilizes Java object serialization.
- */
- public final class Client {
- private static final Logger log = Logger.getLogger(Client.class.getName());
- static final int SIZE = Integer.parseInt(System.getProperty("size", "256"));
- public Client() {
- }
- public void init() throws InterruptedException, SSLException {
- MyProps p = new MyProps();
- String host = p.getHost();
- int port = p.getServerPort();
- startClient(host, port);
- }
- private void startClient(final String host, final int port) throws SSLException, InterruptedException {
- EventLoopGroup group = new NioEventLoopGroup();
- try {
- Bootstrap b = new Bootstrap();
- b.group(group)
- .channel(NioDatagramChannel.class)
- .option(ChannelOption.SO_BROADCAST, true)
- .handler(new ClientHandler());
- Channel ch = b.bind(0).sync().channel();
- ch.writeAndFlush(new DatagramPacket(
- Unpooled.copiedBuffer("QOTM?", CharsetUtil.UTF_8),
- new InetSocketAddress("255.255.255.255", port))).sync();
- } finally {
- group.shutdownGracefully();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment