package com.example.socket.netty.heartbeat;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

public class Client {
	public static void main(String[] args) throws Exception {

		NioEventLoopGroup nioEventLoopGroup = new NioEventLoopGroup();

		Bootstrap bootstrap = new Bootstrap();

		bootstrap.group(nioEventLoopGroup).channel(NioSocketChannel.class)
				.handler(new ChannelInitializer<SocketChannel>() {

					@Override
					protected void initChannel(SocketChannel ch) throws Exception {
						ch.pipeline().addLast(MarshallingCodeFactory.buildMarshallingDecoder(),
								MarshallingCodeFactory.buildMarshallingEncoder(), new ClientHeartBeatHandler());
					}
				});

		ChannelFuture channelFuture = bootstrap.connect("127.0.0.1", Server.PORT);
		
		channelFuture.channel().closeFuture().sync();
		
		nioEventLoopGroup.shutdownGracefully();
	}
}
