package Server;
import java.io.*;
import java.net.*;


public class Server {
	public InetAddress LocalIPA=null;
	public InetAddress LocalIPB=null;
	public InetAddress LocalIPU=null;
	

	public int LocalPortA=0;
	public int LocalPortB=0; 
	public int LocalPortU=0;
	
	public InetAddress PublicIPA=null; 
	public InetAddress PublicIPB=null; 
	
	public Integer PublicPortA=0;
	public Integer PublicPortB=0;

	

	public Server(){
		ServerSocket sockA=null;
		try {
			sockA= new ServerSocket(62000);
		} catch (IOException e) {
			e.printStackTrace();
			System.err.println("Server failed to connect"); 
			System.exit(-1);
		}
		Socket cliA=null;
			try {
				cliA=sockA.accept();
			} catch (IOException e) {
				e.printStackTrace();
				System.err.println("Failed to connect");
				System.exit(-1); 
			} 
			
			
			getInfo(cliA);
			
			
			
			
		
			//////////////////////////////////////////////////////////////////////////////////
			
			//	sendEndpointsB2A(cliA);
				
				try {
					cliA.close();
					sockA.close();

				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				
				
		
					
				}
public void getInfo(Socket client){
	
	 ObjectOutputStream oos=null;
		
			try {
				oos = new ObjectOutputStream(client.getOutputStream());
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
				System.exit(-1); 
			}
		
		ObjectInputStream ois=null;
		    try {
				ois = new ObjectInputStream(client.getInputStream());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				System.exit(-1); 
			}
			String stockname=null;
			try {
				stockname= (String) ois.readObject();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				System.err.println("I/O Exception");
				System.exit(-1);
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				System.err.println("Class NOt Found");
				System.exit(-1);
			}
			System.out.println(stockname.toString()+"--SERVER");
			
			
		
	
}

		
	
		public void sendEndpointsB2A(Socket client){
				ObjectInputStream ois=null;
			    try {
					ois = new ObjectInputStream(client.getInputStream());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					System.exit(-1); 
				}
				ObjectOutputStream oos=null;
			
				try {
					oos = new ObjectOutputStream(client.getOutputStream());
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					System.exit(-1); 
				}
		
			try {
				oos.writeObject(LocalIPB);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				System.exit(-1);
			} 
			
			try {
				oos.writeObject(LocalPortB);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				System.exit(-1);
			} 
			
			try {
				oos.writeObject(PublicIPB);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				System.exit(-1);
			} 
			
			try {
				oos.writeObject(PublicPortB);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				System.exit(-1);
			} 
			try {
				oos.flush();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				System.exit(-1);
			}
			
		}
		
		
	
		
		
		
		
		
	
	
	public static void main(String[] args) {
		Server server=new Server(); 
			
		
	}

}
