| Author |
Message |
|
|
Is this a case sensitivity issue? Java is case sensitive for everything. If your class is MyClass.class then it has to be run with "java MyClass" regardless of the O/S you're on.
Otherwise I'm at a bit of a loss. Have you tried adding the classpath command line argument too? Under Windows I did the following:
is this about the same thing you're doing?
|
 |
|
|
That's kind of wierd as 1.5 is usually pretty easy to use. So I guess I'd ask two things.
The first is to make sure that your path is set to what you expect. Just run "java -version" and make sure it gives you back what you want.
The second is that can you print out what your CLASSPATH environment variable is? It may not be set (which would be good) but if it is it can mess things up. In a Windows Command Prompt window just do an "echo %CLASSPATH%". If you're on a Unix like O/S do a "echo $CLASSPATH".
|
 |
|
|
You declared space for the array but you still need to declare space for each element in the array. Also, remember that arrays are zero based. That means the first element in the array is [0] and the last is, in your case, [3]. Something like:
|
 |
|
|
Do you know what version you're running at home vs school? Older JDK's required a little bit different command line options.
In both Java 1.4 and 1.5 your best bet is to always specify the classpath on the command line.
To compile a program:
To run:
This should work with any JDK that is 1.3 and above. 1.4 and 1.5 include the current directory (the single dot in the second command above) by default unless it is overridden. I feel that it is much clearer to see exactly what is going on by specifiying it myself.
|
 |
|
|
I feel that you kinda posted a work in progress. There are syntax errors and incomplete parts. We'll be glad to help you but it is important for you to help us help you. The implication with "The program should quit everytime when 0 is entered and it isnt" is that you can't figure out where the issue is. But you're code doesn't even compile.
As a hint java equality is tested with a double equals so the code
is not only syntactically wrong but it won't test for zero either. You'll want something more like:
|
 |
|
|
Don't give up - you're getting there.
First thing - remember that each line in Java has to end with a semicolon. So things like:
have to be:
Next, I'm not sure what the last two loops are for - the do work but you never use the results anywhere.
As far as the middle for loop, it does work the way I think you want - it fills up the student array - almost. You declare studentarry as:
But then loop like
You're very close - that 8 should be a 9 as you're doing a less than. The variable "i" will range from 0 to 7 in that loop - not quite what you want.
You keep working and we'll keep helping - you're getting close.
|
 |
|
|
I'm not sure what the issue is - it would help to give us the full code to determine what isn't working. It seems that based on the errors:
we're missing a bit.
|
 |
|
|
The upgrade to PostgresSQL 8.1.0 and Tomcat 5.5.12 has been completed. If you see any issues please let me know!
Thanks for using for hotjoe.com forums.
|
 |
|
|
|
I'm sorry - I don't understand the question. The views mean the number of people who have viewed the thread. If you do not want this thread please click on on the "Private Messages" link above and send me a message and I'll delete the thread.
|
 |
|
|
The core of the server will be based on ServerSocket. This is the base server side class when using TCP sockets.
Let's look at the some of the methods that I'll be using (quotes from the Javadoc):
public ServerSocket(int port) throws IOException
Creates a server socket, bound to the specified port.
This is the basis of our server. We'll create a ServerSocket that, in the Berkeley sockets (regular C sockets on most Unix systems) terminology does a bind() to a particular port. What this means is that once you call this (and assuming that no exceptions get thrown) there will be a socket ready to accept connections on the port we specify. So lets start with a little code to test this:
We'll setup a real build environment in a bit but this can be compiled by hand:
and run with
You can select anything you want for the port number as long as two conditions are satisfied. The first is that, on Unix and Linux the default configuration only allows you to bind to a port number of 1024 and higher. If you try to bind to something less you'll get an exception like:
Secondly, if you try to use a port that is already in use you'll get something like:
Otherwise, you can test that this works by using the telnet program. You'll want to do something like:
(assuming that you're running the client - telnet - and the server on the same machine).
You will get something like:
on the server side and:
in the telnet window. This is exactly what we expect as the server simply closes the new socket once it is done. Note that the exact messages may be slightly different depending on your operating system and the version of Java you're using. These messages were generated on a Fedora Core 3 Linux system using Java version 1.4.2_08.
|
 |
|
|
I'd like to create an article on building a very simple HTTP server. There are other tutorials out there but I'll try my shot at it too. It seems that sockets are a common discussion topic. As part of this the first post will be about the requirements that I'm going to try to satisfy.
The first and most important thing is that the purpose of this is to provide a framework for learning. It is not to produce a production quality web server like Apache or Tomcat. While the code will be high quality I may take shortcuts or leave some features out in the interest of time or clarity. I will try to point out where I feel that a shortcut or non-enterprise design has been used. A side effect of this requirement is we will not use anything except for the classes available in 1.4 J2SE. There are many excellent libraries available for networking. But this is meant to be a learning program. By doing it "by hand" one time I find that you learn significantly more than jumping straight to a thrid party library.
Which leads to the second requirement. I'm going to limit the initial scope to only handle the HTTP GET command. This is the most commonly used HTTP command. However, this means that the first version of the software will not be able to handle form processing. As time permits I will also include the HTTP POST command.
The server should comply with RFC 2616 in the GET area where possible. Where it isn't possible it should work well with any HTTP client. While the majority of the HTTP clients are browsers the server should work equally well with programs such as wget where there is much more limited user interaction.
Lastly, the code will be developed in a Java 1.4 environment. While Java 1.5/5.0 is the current release the intention is to allow the most number of people to benefit from this. 1.5 is still in limited use outside of schools. From what I can see a significant number of people are still using 1.4. Where something might be easier in 1.5 we will try to point that out.
If you'd like to see other requirements please feel free to post it in this thread. We can discuss what else may be useful and add it to the requirements as time permits.
|
 |
|
|
It would help to see your code some but generally you have a ServerSocket that sits and waits in accept(). Once this method returns you have a Socket to communicate over. In many systems you spawn a thread to handle the Socket that was accept()'d so that you can handle multiple clients at the same time.
When the client is done with a socket it will close it. On the server side you'll get some indication that the read failed. Depending on the data you're passing back and forth this might be that you get a null from a read or some other indication. You close that socket and, if your using threads, end that thread. The main thread continues to listen and accept() new connections.
|
 |
|
|
The hotjoe.com forums will be unavailable this weekend, December 3 and 4 sporadically. I will be upgrading both the underlying PostgreSQL database and will be upgrading to Tomcat 5.5.12.
During this time the forum may be unavailable. No posts or other information will be lost.
Thanks for your patience.
|
 |
|
|
|
That sounds correct. If you can just leave it running (for example, put the process in the background in a Unix environment) you should only have to start it once.
|
 |
|
|
shadow wrote:oh ok thanks for clarifying that, also how do I know if the program will be running all the time in order for anyone to post/read messages? is this something to do with the server it would be residing?
This part will be an O/S specific thing. Both Unix and Windows allow you to start processes on reboot of the machine. If the program has a tendency to crash (not that yours would of course, but code from other people sometimes does ) there are different ways to keep the process running depending on the O/S.
shadow wrote:and one las thing, I'm kind of new to this networking and sockets logic and this is the first time I dive into this I'm not that sure how would it work online, since in the localhost I first need to run the program and then I can connect to it through it with telnet...how would it be if it is online?
Pretty much the same way. Assuming that your program wasn't running you'd log into a remote machine somewhere using maybe ssh or telnet. Then you'd start up your program. Once it was running you'd be able to connect to it through either the IP address of the host or, depending on your setup, a name like shadow.somehostname.com. So instead of something like:
you'd do:
|
 |
|
|