File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help Networking book example

 
Al Stumpel
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using teach yourself java by O'Neil and am going through some of their examples. The current problem I have is a socket example. It is compiling correctly, but the program is not running for me at all in netbeans 4.1 or in the command prompt. Any help is greatly appreciated.

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks OK. You'd run the ServerSocketDemo, which will appear to do nothing, and then just leave it running. Now run the SocketDemo. It will contact the ServerSocketDemo, obtain a single random number, print it, and exit. When you run each program you need to supply a number as an argument; you must use the same number for each. "6543" is a personal favorite for this sort of program.
 
Al Stumpel
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I try to run it I get the error message exception in thread "main" java.lang.NoClassDefFoundError: ServerSocketDemo
I get the same message for the Socket Demo.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) From the command prompt, use "cd" to make the current directory be the location of the ServerSocketDemo.class file.

2) Type

java -cp . ServerSocketDemo 6543

3) Open a new command window, "cd" to the location of the SocketDemo.class file

4) Type

java -cp . SocketDemo 6543

It should print a number, then quit.

Why are you having a problem? The short answer is that you've got the CLASSPATH environment variable set, and it doesn't include a "." for the current directory. See this document for more information; read the whole thing, including the linked document and the caveats about not relying on CLASSPATH too much!
[ May 22, 2006: Message edited by: Ernest Friedman-Hill ]
 
Al Stumpel
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic