Results 1 to 2 of 2
  1. #1
    christopherx is offline Member
    Join Date
    Oct 2011
    Posts
    92
    Rep Power
    0

    Default Java Sockets Not connecting over different PCs

    Hey there guys! So I've been writing a chat program over the past few days, just so practice concepts that I've learnt in University (design patterns etc) and I've hit a bit of a stumbling block. I've written the server for my chat program(The server reroutes packets from one client to the other, and it returns data requested by the clients). Now the issue I'm facing is that, over "localhost", the chat program runs completely fine. There isn't an issue. When I change "localhost" to my computer's internal IP (192.168.0.3), and use it on the same computer it's still completely fine. But if I move the client program onto the other computer, I get this error:

    java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Un known Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress( Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at Controllers.ClientProgram.<init>(ClientProgram.jav a:25)
    at Controllers.TestBed.main(TestBed.java:10)
    Exception in thread "main" java.lang.NullPointerException
    at Controllers.ClientProgram.<init>(ClientProgram.jav a:34)
    at Controllers.TestBed.main(TestBed.java:10)
    Exception in thread "Thread-3" java.lang.NullPointerException
    at Controllers.ClientProgram.getOnlineUsers(ClientPro gram.java:65)
    at Views.ChatPage.setOnlineUsersList(ChatPage.java:99 )
    at Controllers.UsersListUpdater.run(UsersListUpdater. java:18)

    I am using port 1234, and i have turned off the firewall on both computers. I've also turned off the firewall that is built into my Virgin superhub rooter, and I have turned on port forwarding from port 1234 to the IP of the server (192.168.0.3).

    I am completely at a loss, and was wondering if you guys have any suggestions?

    This is the constructor for building a client side of the program:

    Java Code:
    public ClientProgram(String username) 
    	{
    	
    		try {
    			client = new Client(new Socket("192.168.0.3",1234),username);
    		} catch (UnknownHostException e) {
    			e.printStackTrace();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		
    		clientView = new ChatPage(this);
    		
    		messageListener = new ClientListener(client.getInputStream(), this);
    		messageListener.start();
    	}
    And here is the code for the server's constructor, showing the server socket.

    Java Code:
    public Server()
    	{
    		try {
    			socket = new ServerSocket(1234);
    			onlineUsers = new ClientLibrary();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    I have several threads. One of them to accept new clients:

    Java Code:
    public void run()
    	{
    		 while(true)
    		 {		 
    			 s.acceptClient();
                             // Inside the acceptClient() method there is a call to serverSocket.accept(). 
    		 }
    	}

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Java Sockets Not connecting over different PCs

    Moved from New to Java

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

Similar Threads

  1. Sockets not connecting over Internet
    By Bestsanchez in forum Networking
    Replies: 5
    Last Post: 05-25-2012, 07:58 AM
  2. Replies: 2
    Last Post: 03-28-2011, 03:06 PM
  3. Java Sockets
    By PhQ in forum New To Java
    Replies: 2
    Last Post: 05-07-2010, 11:34 AM
  4. Java sockets
    By Camzie in forum NetBeans
    Replies: 3
    Last Post: 12-22-2009, 04:39 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
  •