0

hi everyone,

iam trying to connect to server here is the code for connecting:

public void CONNECT_TO()
   {
                    int port=200;


                    if(t1.getText()=="")
                         serv="localhost";
       else
                         serv=t1.getText();

                    try
       {
                        port = Integer.parseInt(t2.getText());

       }
                        catch (Exception e) { }

                    try
                                                  {
                                                                   c_s = new Socket(serv, port);
                                                                   l3.setText("Connected to server " +c_s.getInetAddress()+":" +c_s.getPort());
                                                                   form F=new form();
                                                                   F.show();
                                                                   F.setResizable(false);
                                                                   this.hide();
                                                  }
                                                  catch (UnknownHostException e)
                                                  {
                                                                   System.out.println(e);
                                                                   System.out.println("Error in connecting Server");
                                                                   
                                                  }
                                                  catch (IOException e)
                                                  {
                                                                   System.out.println(e);
                                                                   System.out.println("Error");
                                                                   
                                                  }
   }

It runs fine but when i enter localhost for ip address it gives me the error for the second exception, IOEXCEPTION.

anyone knows why?

thank you

2
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by jwenting
0

ok everyone,

now i can connect to the server, but using netstat -a command which lists the ports available.

This is going to be difficult for user to find the port.

what should i do ?

thank you

0

you're always going to need to know both the IP address AND the port AND the protocol to successfully talk with any server (and that is assuming you also are allowed to talk to it, know the usernames and passphrases needed, etc.).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.