Results 1 to 2 of 2
- 01-23-2013, 12:31 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 92
- Rep Power
- 0
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:
And here is the code for the server's constructor, showing the server socket.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(); }
I have several threads. One of them to accept new clients:Java Code:public Server() { try { socket = new ServerSocket(1234); onlineUsers = new ClientLibrary(); } catch (IOException e) { e.printStackTrace(); } }
Java Code:public void run() { while(true) { s.acceptClient(); // Inside the acceptClient() method there is a call to serverSocket.accept(). } }
- 01-23-2013, 12:32 PM #2
Similar Threads
-
Sockets not connecting over Internet
By Bestsanchez in forum NetworkingReplies: 5Last Post: 05-25-2012, 07:58 AM -
Connecting 3 machines through Sockets and ServerSockets
By Yogesh_P in forum NetworkingReplies: 2Last Post: 03-28-2011, 03:06 PM -
Java Sockets
By PhQ in forum New To JavaReplies: 2Last Post: 05-07-2010, 11:34 AM -
Java sockets
By Camzie in forum NetBeansReplies: 3Last Post: 12-22-2009, 04:39 PM -
Problems with connecting two sockets on the same application.
By jrsofty in forum NetworkingReplies: 0Last Post: 12-01-2009, 01:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks