Re: Client Server
From: Anthony Borla (ajborla_at_bigpond.com)
Date: 12/17/03
- Next message: Kamran Karimi: "process creation: How to know when the command was not found?"
- Previous message: Kamran Karimi: "Button names in a toolbar (as well as text in jTextArea) diappear!"
- In reply to: Anthony Borla: "Re: Client Server"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 16 Dec 2003 23:08:43 GMT
"Anthony Borla" <ajborla@bigpond.com> wrote in message
news:cgqDb.54043$aT.53684@news-server.bigpond.net.au...
>
> "Andrew McGinley" <andrewmc110@hotmail.com> wrote in message
> news:brku13$ol1$1@kermit.esat.net...
> > Hi Everyone
> >
This is a response to a follow-on query the OP e-mailed to me - I thought
I'd share it for comments and possible feedback:
<message>
>
> hello thanks a million for your reply, I really appreciate it.
> However I don't think I was too clear. I want to be able
> to read a file in before I read out to it
>
I'm not sure what you are asking here. Are you saying that you want to
update an existing file with new information ? If so, use the
'RandomAccessFile' object to access a file in both read and write mode. I
should warn you, though, that this works best if you are *replacing* data
that has the same length [e.g. five digits 12345 replaced by five digits
43456] rather than inserting data / deleting data where you need to take
care in not overwriting existing data, or leaving 'gaps' of garbage data.
More technically, it is probably easiest to use, and update, if data is
stored as fixed-length records.
Otherwise, read a file in via a stream, make any required updates, and write
it back out to the same file [if the stream used to access it has been
closed], or to another file [and later delete the original m ], in its
entirety.
>
> In other words the file named details will hold for example
> account number and password
>
> The server reads in the info from this file ,which I have created
> myself and compares it to the data that the client has sent to
> it. If this info is valid then various actions can be performed.
>
> I hope I am making sense.
>
> can you help me out?
>
My response, though it was very general in nature, assumed exactly what you
are now asking. You might care to re-read it a couple more times, but all
your questions were actually answered :) !
Just to recap. You have a file containing an Account Number and a Password
for each client, maybe stored something like this:
12345 xyz<newline>
12432 ghyuj<newline>
23421 eeera<newline>
...
or it could be in another format, several of which I described in my earlier
post.
So, at some point you want the server to read this file in. As I described,
you might do this when you first load the server, or at some later time, or
each time a request is received from a client. In all cases, you will:
* Create a stream object to access the file
* Read the stream, and either store the data somewhere,
say for example, an array, or make use of it there and
then
* Close the stream, thus disconnecting from the file, and
allowing the stream object to be disposed of
When a client request arrives wishing to validate an account number and
password it is merely a case of searching through the server-held data and
making the required comparisons, something similar to the code snippet I
provided in my earlier response.
What, exactly, are you having trouble with ? Is it:
* Reading data into the server ?
* Comparing client-supplied data against server-accessable data ?
If you are not comfortable enough with the Java language then all I can do
is to suggest you complete some the tutorials at the Sun site - these might
be of help:
http://java.sun.com/docs/books/tutorial/java/data/index.html
http://java.sun.com/docs/books/tutorial/essential/io/index.html
I hope this helps.
Anthony Borla
</message>
- Next message: Kamran Karimi: "process creation: How to know when the command was not found?"
- Previous message: Kamran Karimi: "Button names in a toolbar (as well as text in jTextArea) diappear!"
- In reply to: Anthony Borla: "Re: Client Server"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]