Find the answer to your Linux question:
Results 1 to 10 of 10
Dear All, I I have a centos 5.5 machine. I have forwarded both port 22 and 8080 on my router. I can connect on 22 via telnet ip 22 and ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2010
    Posts
    72

    Not able to connect with java listener


    Dear All,
    I I have a centos 5.5 machine. I have forwarded both port 22 and 8080 on my router. I can connect on 22 via telnet ip 22 and even can remotely login into the machine. The problem when I start my java listener program which is listening on 8080 it cant not establish any connection (via telnet ip 8080). I have even add this into the iptables too -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 9000 -j ACCEPT. I have disabled the SELINUX too. What else must I do to make it work any suggestion please? Thank you.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    11,159
    Well, in your command to iptables you specify port 9000, not 8080.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Jul 2010
    Posts
    72
    Dear Rubberman,
    Sorry actually I already update my iptables with 8080 not 9000 any more. What else can be my error ya? Below is my first part of code. Do you find any errors in it? I am typing "telnet ip 8080" from remote pc to connect to this socket listener is this wrong ?

    public static void main(String[] args) {



    try {

    InetAddress Address = InetAddress.getByName("192.168.2.15");
    System.out.println(Address);
    final ServerSocket serverSocketConn = new ServerSocket(8080,-1,Address);



    while (true)

    {

    try

    {

    Socket socketConn1 = serverSocketConn.accept();
    System.out.println("Remote Connection Accepted");

    //new Thread(new ConnectionHandler(socketConn1)).start();

    }

    catch(Exception e)

    {

    System.out.println(e.toString());

    }

    }



    }

    catch (Exception e)

    {

    System.out.println(e.toString());

    //System.exit(0);

    }

    }

  4. #4
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    does netstat -an on the server show port 8080 bound to the address and are you sure its the right address?

  5. #5
    Just Joined!
    Join Date
    Jul 2010
    Posts
    72
    Dear Rubberman,
    Ok I just did netstat -an it shows me local address as 0:ffff:192.68.2.15:8080 and foreign adress as :::*. So what else can be my mistake ya? Thank you.

  6. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    11,159
    Quote Originally Posted by newbie14 View Post
    Dear Rubberman,
    Sorry actually I already update my iptables with 8080 not 9000 any more. What else can be my error ya? Below is my first part of code. Do you find any errors in it? I am typing "telnet ip 8080" from remote pc to connect to this socket listener is this wrong ?

    Code:
    public static void main(String[] args) {
    
    
    
    try {
    
    InetAddress Address = InetAddress.getByName("192.168.2.15");
    System.out.println(Address); 
    final ServerSocket serverSocketConn = new ServerSocket(8080,-1,Address);
    
    
    
    while (true) 
    
    {
    
    try 
    
    {
    
    Socket socketConn1 = serverSocketConn.accept();
    System.out.println("Remote Connection Accepted");
    
    //new Thread(new ConnectionHandler(socketConn1)).start(); 
    
    }
    
    catch(Exception e)
    
    {
    
    System.out.println(e.toString());
    
    }
    
    }
    
    
    
    } 
    
    catch (Exception e) 
    
    {
    
    System.out.println(e.toString());
    
    //System.exit(0); 
    
    }
    
    }
    I don't see you listening on the socket before you accept the connection. For a server, you first need to listen(), and then accept() the connection.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  7. #7
    Just Joined!
    Join Date
    Jul 2010
    Posts
    72
    Dear Rubberman,
    I have checked this few site but I am not allowed to post links here it give me error. but there are all show that ServerSocket serverSocketConn = new ServerSocket(8080,-1,Address); is the listener which is there in my programme. What else do you think I have gone wrong? Thank you.
    I search on google as " java server socket example"

  8. #8
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    looks like your application is binding to ipv6 address, which is probably what the problem is

  9. #9
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    11,159
    Quote Originally Posted by newbie14 View Post
    Dear Rubberman,
    I have checked this few site but I am not allowed to post links here it give me error. but there are all show that ServerSocket serverSocketConn = new ServerSocket(8080,-1,Address); is the listener which is there in my programme. What else do you think I have gone wrong? Thank you.
    I search on google as " java server socket example"
    Yes. Sorry, but I don't do a lot of Java network programming. I read the docs and agree that creating the server socket puts it into a listening state and accept() on it will block until a connection request is made. As for Coopstah13's comment about an IPv6 address, the address you specified is an IPv4 address, but the options to the ServerSocket constructor may be the issue here. You are binding it to a specific local address. Normally, you would just instantiate it with the port number you are going to listen on. Try that and see if it works. Here is the Java doc page for that class: ServerSocket (Java 2 Platform SE 5.0)
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  10. #10
    Just Joined!
    Join Date
    Jul 2010
    Posts
    72
    Dear Rubberman,
    Yes I have solve my problem actually is due to iptables settings some thing wrong due to port forwarding. Anyway thank you to all for your kind help too. Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •