Trixmix
Trixmix

Reputation: 81

My program hangs on a line when reading input from a server.. Java

I have a client / server application exactly like in this link. When I say exactly I mean I copied and pasted it and adjusted the ip and port stuff to my computer.

http://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html

When I get to the part where I need to read a line from the server(in the client) my program just hangs and doesn't continue. Here is the line:

while ((fromServer = in.readLine()) != null) {

Even its null it doesn't continue it just gets stuck on this line... How do I fix it?

Upvotes: 0

Views: 209

Answers (1)

Kevin Wang
Kevin Wang

Reputation: 3330

in.readLine(), like most readers in Java, works hangs the application (waits) until it gets some data to read.

My guess is that your client isn't receiving any data at all, which is why you're getting the hang. Make sure your client is connecting properly, your server is set up correctly, and the server is actually sending data to your client (and that it's actually getting to your client).

Upvotes: 2

Related Questions