aspose file tools*
The moose likes Bunkhouse Porch and the fly likes Head First Java Chapter 15 Questiion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Books » Bunkhouse Porch
Bookmark "Head First Java Chapter 15 Questiion" Watch "Head First Java Chapter 15 Questiion" New topic
Author

Head First Java Chapter 15 Questiion

Michael Hall
Greenhorn

Joined: Dec 17, 2005
Posts: 21
In chapter 15 of Head First Java I want to try out the SimpleChatClient and VerySimpleChatServer programs but I only have one computer. Is there a way I can set up a situation that passes as a server and a terminal on my desktop computer so I can run those programs in chapter 15? - Thanks
Kj Reddy
Ranch Hand

Joined: Sep 20, 2003
Posts: 1704
You can use your desktop as sever and client.
Steve Gibson
Ranch Hand

Joined: Jan 17, 2006
Posts: 37
If you notice in all their client/server examples the remote IP address is 127.0.0.1 which is yout local loopback (aka localhost) ip address. So what your really are doing is an interprocess call.

Be aware that the example in chap18 ServiceServer does not work if you seperate out the class's into seperate directories. It only works if the service class's are in the same directory as the client. The code does not send the service's to the client as indicated in the sample text. I emailed Bert Bates about it, hopefully it will make the errata for the book.


An insane man is perfectly sane in his own mind - cira 1984 a very young chemically altered S.Gibson<br /> <br />Yes we do build our software idiot proof, problem is they keep building better idiots. - (used by S.Gibson to break the tension during a confernece call with the CIO)
Michael Hall
Greenhorn

Joined: Dec 17, 2005
Posts: 21
Chapter 18? ServiceServer?
In the Head First Java book the Chat Client I am talking about is in Chapter 15 (at least in my version) and consists of VerySimpleChatServer and SimpleChatClient. Anyway when I run the server in one command prompt window and the client in another window and type in text in the client and send it I get the following errors:

java.lang.NullPointerException
at VerySimpleChatServer$ClientHandler.run(VerySimpleChatServer.java:19)
at java.lang.Thread.run(Unknown Source)

Here is code:


Line 19 is - while((message=reader.readLine()) != null){

Help - No Clue.
Steve Gibson
Ranch Hand

Joined: Jan 17, 2006
Posts: 37
Originally posted by Michael Hall:
Chapter 18? ServiceServer?


2 things...

1.My chapter 18 referece was just letting you know that the example really dosen't work as advertised.

2. In your ClientHandler class code for the chat server, you never actually created (instantiated) the BufferedReader (the missing code is in bold/italics below). :

public ClientHandler(Socket clientSocket){
try{
sock=clientSocket;
InputStreamReader isReader=new InputStreamReader(sock.getInputStream());
reader = new BufferedReader(isReader);
} catch(Exception ex) {ex.printStackTrace();}
}


So in your original code the line:

while((message=reader.readLine()) != null)

reader was pointing to (referencing) nothing (null), because reader had never been instantiated (created).




[ March 01, 2006: Message edited by: Steve Gibson ]
[ March 01, 2006: Message edited by: Steve Gibson ]
Michael Hall
Greenhorn

Joined: Dec 17, 2005
Posts: 21
Well, That did the Trick. It works fine. Thanks a lot.
I assume since you are a greenhorn that you are not THE Steve Gibson.
Steve Gibson
Ranch Hand

Joined: Jan 17, 2006
Posts: 37
Originally posted by Michael Hall:
Well, That did the Trick. It works fine. Thanks a lot.
I assume since you are a greenhorn that you are not THE Steve Gibson.


I'm not sure who THE Steve Gibson is..... the only one I can think of is the SpinRite Steve Gibson, in which case I'm not :-)

I'm only a greenhorn on this board, I've been coding since 1987 in RPGIII, RPGIV, ILE-RPG, C (win sdk), VB (all versions) then did a long stint in management. Now I'm back Coding in C# and Java.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First Java Chapter 15 Questiion