Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFJ Example problem, please help

 
Rama Krishna Yalamanchili
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rama Krishna Yalamanchili
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ufffff.....
Got the error...
new is not required.......
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Instead of

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

The listing in the book is:
Socket sock = serverSock.accept();
Which should work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic