(I'm drinking, so excuse any poor grammar/spelling/bad explanations).
I have an assignment due 2 hours ago, but I can get it done 24 hours past the due date with -20%. I've never done client-server applications before. If it seems like I've given rediculously little information, don't yell at me, just leave, I'm sorry. I'll probably get no answers.
I don't want to post a lot of code, I just want input from anyone who's very familiar with client-server Java programs. I'm not going to explain this very well at all, and it will probably only be understandable to someone who knows about the subject very well. I only have one basic question, near the end, the bolded text. The rest is just background information.
in = new Scanner(socket.getInputStream());
out = new PrintWriter(socket.getOutputStream());
That is in the Server's Service, and there are similar variables in the client for getting input and output from the server.
It seems that sometimes, when I go out.println("some message") in the server which should be sent to the in.nextLine() in the client, it will return an empty string. I have a loop which prints a few messages. But I've traced the program several times, printing out each message before it's sent, and there is no reason at all the server should be printing out an empty string, ever. But it does. So I must not be understanding something.
So I'm wondering, does in.nextLine() wait for some String from the server before returning the message, or does it just return an empty string if there is no message right away? Do I have to write a while(!in.hasNext()); before every in.nextLine(), or something similar?
This is the only thing I can see might possibly be happening. If it isn't this, I might just have to give up on this assignment, becuase I don't know what else to try. I've tried everything I can think of.
|
|
Bookmarks