wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HFJ Example problem, please help" Watch "HFJ Example problem, please help" New topic

HFJ Example problem, please help

Rama Krishna Yalamanchili

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();
catch(IOException ex) {

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.

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

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

Joined: Oct 14, 2002
Posts: 8806
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
Similar Threads
Sending a file over socket
Socket connection program works for localhost but not for other ip
Chapter 15 Head First - DailyAdviceClient and DailyAdviceService
new to sockets/networking
client-server error