Results 1 to 5 of 5
  1. #1
    kievari is offline Member
    Join Date
    Nov 2009
    Posts
    28
    Rep Power
    0

    Default client server problem

    Hi,
    I'm trying to learn client-server programming in Java.
    I have a Linux box that is running a server program with the port number 1564.
    I wrote a java-client to connect to this server and communicate with.
    I have a LAN and I ran the java-client on it, everything works fine. This is how I made a socket inside my LAN:
    Java Code:
    Socket skt = new Socket(InetAddress.getByName("192.168.0.5"), 1564);

    The next step is to try to connect via internet. My LAN is behind a DLink-dir320 router. This router has an admin interface with port forwarding facility. I defined the port 1564. It is obligatory to also mention the name of the protocol for the communication with the defined port. I still don't know how to do this in my Java program, as I don't use a standard protocol like HTTP, I just gave a random name. Then I saved changes. My Linux machine has not a firewall (I'm testing things only!). Finally, I changed the IP in my java-client to point to the public IP that my ISP assigned me (statically). I have another Linux box connected to this router and running Apache, and I serve one site on it and it is working correctly, so no problem with the IP. Now the jclient defines the socket this way:
    Java Code:
    Socket skt = new Socket(InetAddress.getByName("89.361.21.152"), 1564);
    When I run it what happens as you guess? Nothing works! :D

    My one and only guess about it is the protocol name under the router, but how to solve it? Or maybe you know that the problem must be somewhere else? Also, even though I used try-catch and various possible exceptions defined, I don't receive any error! Well program ran in LAN right, so has no problem itself probably, then how to debug in such a case?

    Any idea is very appreciated :)
    (English is not my native language)

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    You might try taking out the 'getByName', as it's superfluous and might be causing problems if your IP is not in a DNS table (which it surely isn't). Also, sometime port number lower than 10000 are locked out, so you might try a higher port number.

    Java Code:
    Socket skt = new Socket("89.361.21.152", 1564);

  3. #3
    kievari is offline Member
    Join Date
    Nov 2009
    Posts
    28
    Rep Power
    0

    Default

    Quote Originally Posted by toadaly View Post
    You might try taking out the 'getByName', as it's superfluous and might be causing problems if your IP is not in a DNS table (which it surely isn't). Also, sometime port number lower than 10000 are locked out, so you might try a higher port number.

    Java Code:
    Socket skt = new Socket("89.361.21.152", 1564);
    Thank you Toadaly, I took out 'getByName', and also defined the port as 10500, but it didn't work either :(

    Again from inside LAN it works fine, but for outside, it can't.

    The reason should not be that I am not using a known protocol like HTTP, but this came to my head because in my previous project I wrote an XML-RPC client under Java that connected via my Apache server to Joomla XML-RPC server, and on the same IP it worked fine! I used:

    Java Code:
    	     
    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    	     try {
    			config.setServerURL(new URL("http://89.361.21.152:80/brian/xmlrpc/"));
    		} catch (MalformedURLException e1) {
    			e1.printStackTrace();
    		}
    So may be this is all because of the protocol name? Any more suggestion please? :confused:
    Last edited by kievari; 02-12-2010 at 08:27 AM.

  4. #4
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    I doubt it's the protocol name. I've done things exactly like what you're trying to do....and really, so does every peer-to-peer system out there.

    I'd guess it's either a bug in your code, you have the IP wrong, or it's a router/firewall issue.

  5. #5
    kievari is offline Member
    Join Date
    Nov 2009
    Posts
    28
    Rep Power
    0

    Default

    Quote Originally Posted by toadaly View Post
    I'd guess it's either a bug in your code, you have the IP wrong, or it's a router/firewall issue.
    THANK YOU!

    The problem was with my Linux box! It is connected to my router, and I forgot to point the IP of Default Gateway in it to the router!

    now it WORKED :D

Similar Threads

  1. Client to Server, ClassNotFound Package Problem
    By pwnzer in forum New To Java
    Replies: 3
    Last Post: 11-07-2009, 10:17 PM
  2. Simple server/client text problem
    By Singing Boyo in forum New To Java
    Replies: 5
    Last Post: 06-02-2009, 11:33 AM
  3. Client Server socket problem - help needed
    By kellaw in forum Threads and Synchronization
    Replies: 6
    Last Post: 10-03-2008, 07:49 PM
  4. passing info between server/client problem
    By DarkBlaze in forum New To Java
    Replies: 13
    Last Post: 07-24-2008, 04:14 AM
  5. client-server communication problem
    By revathi17 in forum New To Java
    Replies: 1
    Last Post: 08-09-2007, 03:21 PM

Posting Permissions

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