Hi,
I am trying to read the ip and port number from xml file and using its value in my code. But I am facing problem to connect to server through ip and port number which I get from xml file. However when I hard code the value itts working fine.
Please let me know what could be the possible reason for this. Thanks!!!!!!
public class Client {
 
    /**
     * @param args the command line arguments
     */
 
    public static connection conn;
    public static void main(String[] args) throws Exception{
        // TODO code application logic here
 
        System.out.println("Client Signing In");
 
        System.out.println("Client Connection Establish");
        Global.initial();
        System.out.println(Global.ip);
        System.out.println(Global.port);
        //conn = new connection("127.0.0.1",9081);
        conn = new connection(Global.ip.trim(),Global.port);
 
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Login().setVisible(true);
            } }); 
 
        System.out.println("Inside Client");
        chat cw = new chat();
        cw.setnos(conn.getNos());
 
 
        String str  = conn.getNis().readLine();
 
 
        while(!str.equals("end"))
                {
 
                    cw.getTa().append(str+"\n");
 
                    str=conn.getNis().readLine();
 
                }
        conn.getNos().println("end");
 
        System.exit(0);
 
        System.out.println("Client Signing out");
 
    }
}
 
class connection 
{
    Socket soc;
    PrintWriter nos;
    BufferedReader nis;
 
    public Socket getSoc() {
        return soc;
    }
 
    public PrintWriter getNos() {
        return nos;
    }
 
    public BufferedReader getNis() {
        return nis;
    }
 
    connection(String ip,int port) throws IOException
    {
        System.out.println("Inside connection");
        System.out.println(ip);
        System.out.println(port);
        soc=new Socket(ip,port);
        nos = new PrintWriter(
                new BufferedWriter(
                new OutputStreamWriter(
                soc.getOutputStream())), true);
        nis = new BufferedReader(
                new InputStreamReader(
                soc.getInputStream()));
    }
}
 
class Global extends DefaultHandler
{
    public static String ip;
    public static int port;
    private boolean isip;
    private boolean isport;
    static void initial()
     {
      try{
       SAXParserFactory sf = SAXParserFactory.newInstance();
       SAXParser sp = sf.newSAXParser();
       FileInputStream fis = new FileInputStream("client.xml");
       Global g = new Global();
       sp.parse(fis, g);
      }
      catch(FileNotFoundException e)
      {
          System.out.println("File Not Found Exception");
      }
      catch(ParserConfigurationException e)
      {
          System.out.println("Parse Configuration Exception");
      }
      catch(SAXException e)
      {
          System.out.println("SAEException from sp.parse");
      }
      catch(IOException e)
      {
          System.out.println("IOE");
      }
 
    }
 
    @Override
    public void startDocument() throws SAXException {
        super.startDocument();
    }
 
    @Override
    public void endDocument() throws SAXException {
        super.endDocument();
    }
 
    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
        super.startElement(uri, localName, qName, attributes);
 
        if(qName.equalsIgnoreCase("ip"))
        {
            isip = true;
        }
        else if(qName.equalsIgnoreCase("port"))
        {
            isport = true;
        }
    }
 
    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
        super.endElement(uri, localName, qName);
        if(qName.equalsIgnoreCase("ip"))
        {
            isip = false;
        }
        else if(qName.equalsIgnoreCase("port"))
        {
            isport = false;
        }
    }
 
    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {
        super.characters(ch, start, length);
        String str = new String(ch,start,length);
        str = str.trim();
        if(isip)
        {
            ip = str;
        }
        else if(isport)
        {
            port = Integer.parseInt(str);
        }
    }
}