LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-01-2005, 09:29 AM   #1
mrobertson
Member
 
Registered: May 2005
Posts: 275

Rep: Reputation: 30
Error in coding a java server.


I am currently coding a java server in the vi text editor using a knoppix linux system. I have used the following code.

import java.net.*;
import java.io.*;

public class Server {

public static void main(String[] ar) {

int port = 6666;
try {
ServerSocket ss = new ServerSocket(port);
System.out.println("Waiting for a client...");
Socket socket = ss.accept();
System.out.println("Got a client ... !");
System.out.println();

InputStream sin = socket.getInputStream();
OutputStream sout = socket.getOutputStream();

DataInputStream in = new DataInputStream(sin);
DataOutputStream out = new DataOutputStream(sout);
String line = null;
while(true) {
line = in.readUTF();
System.out.println("The client just sent me this line : " + line);
System.out.println("Waiting for the next line...");
System.out.println();
}


} catch(Exception x) {
x.printStackTrace();
}
}
}

I am getting the following errors:

No encode delegate for this image format "java.net.*"
No encode delegate for this image format ".io.*"
line 4: public: command not found
line 6: syntax error near expected token "("
line 6: public static void main(String[] ar) {


Does anyone know what is causing these errors and what I can do to fix them?
 
Old 06-01-2005, 03:38 PM   #2
huibert.alblas
Member
 
Registered: Jan 2004
Location: Duesseldorf /Germany
Distribution: Gentoo amd64 / Debian
Posts: 226

Rep: Reputation: 30
Your codes looks ok.

What steps do you take to execute the code.
(You know you have to compile it fisrt :-)

Your Error messages do not look like nornal error messages.

Please give more info.
 
Old 06-02-2005, 07:09 AM   #3
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
I used chmod 711 JavaServer1 and then typed JavaServer1 on the next command line. What steps should I be taking? Is there another way to go about it? Do I need to import libraries that handle the java socket class?
 
Old 06-02-2005, 01:37 PM   #4
huibert.alblas
Member
 
Registered: Jan 2004
Location: Duesseldorf /Germany
Distribution: Gentoo amd64 / Debian
Posts: 226

Rep: Reputation: 30
You need to be more exact in your description:

you must have run
"javac Server.java"
at some point.

This should create a file named Server.class

To run the program you need to do something along the lines like this: "java -cp . Server"

Trying to execute a Java classfile directly will not work.

If you don't understand any of this, I recomend you start reading something like "thinking Java" by Bruce Eckel
http://www.bruceeckel.com/javabook.html

Or if you don't want to buy the book (yet) :
http://www.codeguru.com/java/tij/tij_c.shtml
The book is free (but you can buy a dead tree copy at your bookstore of choise)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding java in a php script mrobertson Programming 44 06-27-2005 01:16 PM
coding a php server mrobertson Linux - General 22 06-05-2005 01:06 PM
a Distribute for a server and coding blackman890 Linux - Distributions 5 03-26-2005 08:51 PM
error coding a function in c shams Mandriva 1 07-28-2004 12:09 AM
What is the main used program for coding Java? Tyir Programming 2 10-20-2003 08:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration