This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using streams in a java web server  RSS feed

 
Dora Smith
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to build a java webserver for my Networks class. I don't need to code up a client--I can just use a browser to request a resource (txt, jpeg, etc). I think I have the header part working, but the files I send aren't showing up in the browser window. What am I doing wrong? Do I need to use a different stream class? Here's my code:

 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I can tell, that code should be writing data to a socket's output stream. (Or it could be throwing an exception: have you eliminated that possibility?) Whether the other end of the socket is connected to your browser in some way is anybody's guess. So there are many possibilities for your failure to see data in the browser.

Have you debugged that code to see whether it is actually sending any data to the socket? If so, then it's likely your problem is elsewhere.
 
Dora Smith
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not throwing any exceptions, and I have debugged it a little to make sure it's actually sending stuff. I tried requesting an html document just now and it showed up on the browser just fine--it's just everything else that doesn't. Does that mean I have to wrap everything in an html file before I send it, or something? I have no idea.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're saying that if the document you send contains valid HTML then your browser displays it, and if it contains something else then it doesn't? Then what were you thinking? Of course that code is sending the data, it's just that the browser might not know what to do with it. Do you have code which decides what Content-Type header to send based on the data you're sending?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!