Results 1 to 1 of 1
Thread: Connection timed out
- 01-11-2013, 10:26 AM #1
Senior Member
- Join Date
- Jun 2011
- Posts
- 100
- Rep Power
- 0
Connection timed out
I made a simple client-server chat programs using sockets and so far it works, then I tried to switch the programs around to see the connection with VB program (made by my colleague) and finally get a VB client-Java Server works...however on the other way around with Java as client, I get connection timed out.
Here's the code :
and here's the error message in console (the vb server program runs and I'd checked that the port used is on listening state using netstat) :Java Code:public static void main(String[] args) throws UnknownHostException { Socket clientSocket = null; DataOutputStream os = null; DataInputStream is = null; PrintStream output; InetAddress addr = InetAddress.getByName("192.168.1.140"); String hostname = addr.getHostName(); try { clientSocket = new Socket(hostname, 11111); os.writeBytes("Socket connection : " + clientSocket); os = new DataOutputStream(clientSocket.getOutputStream()); is = new DataInputStream(clientSocket.getInputStream()); } catch (UnknownHostException e) { System.err.println("Don't know about host: " + hostname); } catch (IOException e) { System.err.println("Couldn't get I/O for the connection to: " + hostname); e.printStackTrace(); System.out.println(e.getMessage()); } if (clientSocket != null && os != null && is != null) { try { while (true) { System.out.print("Client: "); Scanner scInput = new Scanner(System.in); String sInput = scInput.nextLine(); os.writeBytes(sInput); output = new PrintStream(clientSocket.getOutputStream()); String responseLine; BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); while ((responseLine = in.readLine()) != null && !responseLine.equalsIgnoreCase("bye")) { System.out.println("Server: " + responseLine); System.out.print("Client: "); Scanner scInputX = new Scanner(System.in); String sInputX = scInputX.nextLine(); os.writeBytes(sInputX); if (responseLine.indexOf("Ok") != -1) { break; } } os.close(); System.out.println("os closed"); is.close(); System.out.println("is closed"); clientSocket.close(); System.out.println("client socket closed"); } } catch (UnknownHostException e) { System.err.println("Trying to connect to unknown host: " + e); } catch (IOException e) { System.err.println("IOException: " + e); } } }
Couldn't get I/O for the connection to: 192.168.1.140
Connection timed out: connect
java.net.ConnectException: Connection timed out: connect
at java.net.TwoStacksPlainSocketImpl.socketConnect(Na tive Method)
at java.net.AbstractPlainSocketImpl.doConnect(Abstrac tPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress( AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractP lainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.j ava:157)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.j ava:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
at javaapp2.JavaApp2.main(JavaApp2.java:27)
I don't see any problem since the same code works with my java server program, but maybe someone can see the problem here.
Second to the problem, I want to improve this, the currently running (with Java as both client and server), I can only make it as far as either server/client starts the chat...I want to be able to make it kind of simultaneous so that while it listens it can also starts. So far as my guess, it may have to do with threading, but if there's anything I'd like to hear it.
Thanks in advance,First is to make something usable, next is to aim for perfection which means a never ending improvements.
Similar Threads
-
javamail, Connection timed out
By OmerHalit in forum NetworkingReplies: 11Last Post: 04-12-2010, 07:02 AM -
Connection Timed Out
By sukatoa in forum NetworkingReplies: 2Last Post: 10-27-2009, 03:20 PM -
connection timed out in my java code
By santhosh_el in forum AWT / SwingReplies: 4Last Post: 10-22-2009, 12:24 PM -
solution for connection timed out
By santhosh_el in forum NetworkingReplies: 0Last Post: 10-03-2009, 07:55 AM -
i am getting connection timed out
By santhosh_el in forum NetworkingReplies: 1Last Post: 08-25-2009, 06:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks