Results 1 to 8 of 8
  1. #1
    rolls is offline Member
    Join Date
    Mar 2009
    Posts
    7
    Rep Power
    0

    Default Java chat program, works on single PC, but not over internet?

    I got bored so I started writing a chat client in java, its IRC style, a server and as many clients as you want. It works fine on a single computer (using 127.0.0.1 as the IP) but not over the internet.

    I've tried running the server and client on my home PC, set up the ports to be forwarded on my router and enabled them in the windows firewall but I get the error "Connection refused" when trying to connect using my external IP address, same with me running the server and a mate running the client.

    The class chatHandler was basically stolen off the internet, the rest I wrote myself or modified bits of code to suit. I wrote it in netbeans with the GUI builder.

    I've hosted both projects in the single zip, if you want to run the application just open the .jar file in the dist folders, or view the source via the src folder, or alternatively you can load the project up in NetBeans so its easier to play with the GUI.

    So yeah if anyone can help me out with why its not working that'd be great, I've added the port to my firewall (default 60111). My ultimate goal is to implement an actual protocol so it isn't just sending plain text, then I can easily send files to mates etc.

    rapidshareDOTcom/files/208309140/ChatProgram.zip.html
    Last edited by rolls; 03-12-2009 at 01:52 PM.

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

    Default

    127.x.x.x is a LAN IP not an internet IP. You have to know what the internet IP is.

  3. #3
    rolls is offline Member
    Join Date
    Mar 2009
    Posts
    7
    Rep Power
    0

    Default

    Quote Originally Posted by toadaly View Post
    127.x.x.x is a LAN IP not an internet IP. You have to know what the internet IP is.
    ROFL I realise this, 127.0.0.1 is the local loopback, using this IP it works fine, when trying my ACTUAL WEB IP address it does not work. This is the problem that I am trying to fix.

  4. #4
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Implement your static IP which ISP gave you.

  5. #5
    rolls is offline Member
    Join Date
    Mar 2009
    Posts
    7
    Rep Power
    0

    Default

    I don't have a static IP, why should it matter though? as long as I don't reset my modem it won't change for up to 3 months at a time.

    Even then as long as I know my IP and tell the client it should still connec tyes ?

  6. #6
    MasterD is offline Member
    Join Date
    Mar 2009
    Location
    Germany
    Posts
    22
    Rep Power
    0

    Default

    As you said you added the port to your firewall, does your modem has another firewall installed or are you additionally using a software firewall? Since, afaik, adding your public IP + a forwarded port should do for connection.

  7. #7
    rolls is offline Member
    Join Date
    Mar 2009
    Posts
    7
    Rep Power
    0

    Default

    I have added java.exe, javaw.exe, the ports Im using to the windows firewall and also the ports I am using to my router.

    I have also tried changing :
    server = new ServerSocket(port);

    to:
    InetAddress IP = InetAddress.getByName(IPAddress);
    server = new ServerSocket(port, backlog, IP);

    (IPAddress = 192.168.1.3 my lan NIC)

    As I believe it was binding to my local loopback adaptor, hence not seeing any packets when using a packet analyser, however now I get an exception, after printing a stacktrace I get this.

    However I can now connect using 192.168.1.3 just not using my external IP address.

    java.net.ConnectException: Connection refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl .java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSoc ketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.j ava:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.j ava:366)
    at java.net.Socket.connect(Socket.java:519)
    at java.net.Socket.connect(Socket.java:469)
    at java.net.Socket.<init>(Socket.java:366)
    at java.net.Socket.<init>(Socket.java:180)
    at chatclient.Client.run(Client.java:60)
    at java.lang.Thread.run(Thread.java:619)



    Why is my connection getting refused? I've set up a virtual server and port forwarding on my router, and turned off the windows firewall.
    Last edited by rolls; 03-31-2009 at 02:08 PM.

  8. #8
    rolls is offline Member
    Join Date
    Mar 2009
    Posts
    7
    Rep Power
    0

    Default

    Yey I got it working, for some reason the person I was testing it with it didn't work for but it does with everyone else.

Similar Threads

  1. Replies: 2
    Last Post: 12-27-2008, 09:02 PM
  2. Replies: 2
    Last Post: 11-18-2008, 11:44 PM
  3. Develop chat program using SCTP protocol
    By rams in forum Networking
    Replies: 0
    Last Post: 11-03-2008, 06:07 AM
  4. Replies: 2
    Last Post: 07-28-2008, 08:32 PM
  5. Java Program chat
    By susan in forum Advanced Java
    Replies: 1
    Last Post: 07-25-2007, 10:05 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
  •