aspose file tools*
The moose likes Beginning Java and the fly likes HFJ Example problem, please help 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 » Java » Beginning Java
Bookmark "HFJ Example problem, please help" Watch "HFJ Example problem, please help" New topic
Author

HFJ Example problem, please help

Rama Krishna Yalamanchili
Greenhorn

Joined: Feb 11, 2004
Posts: 25
Hi ranchers,
I am trying to implement this piece of server code from HFJ.
import java.io.*;
import java.net.*;
public class DailyAdviceServer {

String adviceList[] = {" Take smaller bites. "," Go for the tight jeans. "," Just for today Be Honest ","You might want to rethink taht Haircut. "," No they do not make you fat. "," Wierd ist not Wierd. "};

private void go() {
try {
ServerSocket servSock = new ServerSocket(4242);

while(true) {
"* ERROR *" Socket sock = new servSock.accept();

PrintWriter Writer = new PrintWriter(sock.getOutputStream());
String advice = getAdvice();
Writer.println(advice);
Writer.close();
System.out.println(advice);
}
}
catch(IOException ex) {
ex.printStackTrace();
}

}
It is giving me the error,
C:\Java_Examples>javac DailyAdviceServer.java
DailyAdviceServer.java:14: package servSock does not exist
Socket sock = new servSock.accept();
^
1 error
Can anyone say if i have to import anything extra or is there a typo somewhere i overlooked......
Thanks for the help in advance.
YRK


You are not fed, if you dont ask. <img src="wink.gif" border="0"> <p>SCJP 1.4, i2CP, IBM s390 CP
Rama Krishna Yalamanchili
Greenhorn

Joined: Feb 11, 2004
Posts: 25
Ufffff.....
Got the error...
new is not required.......
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8829
    
    5
Hi,
Instead of

* ERROR *" Socket sock = new servSock.accept();

The listing in the book is:
Socket sock = serverSock.accept();
Which should work.


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
 
jQuery in Action, 2nd edition
 
subject: HFJ Example problem, please help