my dog learned polymorphism*
The moose likes Java in General and the fly likes need some help.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "need some help...." Watch "need some help...." New topic
Author

need some help....

vegard ulv
Greenhorn

Joined: Apr 18, 2004
Posts: 7
ive done a server prog, that reads http req...
now i need i program taht can get req from the server prog. to read a txt file and to write a txt file please help:_
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
It's entertaining reading code in a language other than my own. Looks pretty much on the money tho.
What you're missing in your HandlelisteKlient is some code to read the request, figure out what is being asked for, and pump that back out.
HTTP GET requests are pretty easy to read. You can read headers with readln because they are terminated with newlines. Stop when you get a blank one.
The first header says "GET resource HTTPVersion". You can parse it on spaces and the middle word is the resource the client is asking for. You'll have to know how to relate that request to a path on your server.
You'll also want to send some response headers in front of your data. I send these two:
HTTP/1.1 200 Ok
Content-Type: text/plain
followed by a blank line, then start writing the requested file.
Lemme know if that made enough sense to go on. I can post parts of my Wiki server on my web site if that's not too much help - some folks really like to go it on their own.
[ May 05, 2004: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
vegard ulv
Greenhorn

Joined: Apr 18, 2004
Posts: 7
lol cheers somtin like this, but i still need it to write to a txt file on the server
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
FWIW: Here's part of my Wiki server that deals reading GET and POST requests, including multipart file uploads. The MessageReader parses request headers. The Response object writes response headers.
http://www.surfscranton.com/files/HTTPServer.zip
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need some help....