

package com.xmr.net;
import com.xmr.core.Log;
import java.net.InetSocketAddress;
import java.util.concurrent.Executors;

import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelException;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
/**
 *
 * @author Adil
 * Class for TCP interfaces
 */
public class TCPConn {
    private NioServerSocketChannelFactory CFactory;
	private ServerBootstrap SBootstrap;
	public int Port;
    
        public TCPConn(int Port){
        this.CFactory = new NioServerSocketChannelFactory
				(
						Executors.newCachedThreadPool(),
                                                Executors.newCachedThreadPool()
				);
        
        this.SBootstrap = new ServerBootstrap(CFactory);
        
        bootSock();
        }
        private void initSock(){
        
        ChannelPipeline cpipeline = this.SBootstrap.getPipeline();
        //cpipeline.addLast("Encoder",new NetworkEncoder());
        
        }
        public void bootSock(){
        try{
         
        this.SBootstrap.bind(new InetSocketAddress(Port));
        }catch(ChannelException ce){
        Log.WriteWarning("Socket did not connect");
        System.exit(1);
        }
        }
        public void Close(){
           
           SBootstrap.releaseExternalResources();
           Log.WriteInfo("Network pipelines have closed");
        }
        
}
