Results 1 to 6 of 6
  1. #1
    Bestsanchez is offline Member
    Join Date
    Jan 2012
    Location
    The Coffee Pot
    Posts
    36
    Rep Power
    0

    Default Sockets not connecting over Internet

    I have a chat program that works perfectly on a local network, but when I try to connect through the internet I have problems. My server is running on my laptop at home with a serversocket listening on port 55555. When I run my client socket trying to connect to my laptops public IP it actually connects, but If I make my client into a jar and/or run it on a school computer, it fails to connect. And yes my router is set to forward port 55555 to my laptops local IP.

    Relevant code:

    Server
    Java Code:
    import java.net.*;
    import java.util.*;
    import java.io.*;
    
    //This handles all of the Clients in the Server.
    public class Server{
    	private ServerSocket serverSocket;
    	private Socket socket;
    	private ArrayList<User> users;
    
    	//Creates a new Server
    	public Server(){
    		// Attempt to create server socket
    		try{
    			serverSocket = new ServerSocket(55555);
    		}
    		catch(IOException e){
    			System.out.println("Could not open server socket.");
    			return;
    		}
    		System.out.println("Socket " + serverSocket + " created.");
    		users = new ArrayList<User>();
    		new Connect().start();
    	}
    Client connect method:
    Java Code:
            public void connect() throws UnknownHostException, IOException{
    		socket = new Socket("67.189.11.114", 55555);
    		in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    		out = new PrintWriter(socket.getOutputStream(), true);
    		new Input().start();
    	}
    (67.189.11.114 is my laptops public IP)

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: Sockets not connecting over Internet

    Instead of just print error message "could not open server socket", can you print the real error stack trace for us to get better information on the exception might produced by you code.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,235
    Rep Power
    19

    Default Re: Sockets not connecting over Internet

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Bestsanchez is offline Member
    Join Date
    Jan 2012
    Location
    The Coffee Pot
    Posts
    36
    Rep Power
    0

    Default Re: Sockets not connecting over Internet

    No the serversocket opens up just fine, it's the Client that that can't connect. The client socket just times out and throws a ConnectException.

  5. #5
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: Sockets not connecting over Internet

    Can you access it using telnet? Is there any possibility that you work behind a firewall and it block access to that port (55555)?
    Last edited by wsaryada; 05-25-2012 at 06:34 AM.

  6. #6
    Bestsanchez is offline Member
    Join Date
    Jan 2012
    Location
    The Coffee Pot
    Posts
    36
    Rep Power
    0

    Default Re: Sockets not connecting over Internet

    It works now, it was my firewall.

Similar Threads

  1. Replies: 0
    Last Post: 02-02-2012, 08:13 AM
  2. Replies: 2
    Last Post: 03-28-2011, 03:06 PM
  3. RMI through Internet.???
    By bach_meoden in forum Networking
    Replies: 8
    Last Post: 05-19-2010, 02:48 PM
  4. My Web App on Internet
    By orion_mcl in forum Advanced Java
    Replies: 1
    Last Post: 03-14-2010, 09:13 PM
  5. Replies: 0
    Last Post: 12-01-2009, 01:04 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
  •