Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need some help....

 
vegard ulv
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
vegard ulv
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic