Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

socket output writing problem

 
Jeff Yan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey,

im having trouble getting my java server to write to the socket to get a browser to read the html it has been sent, the browser just waits for a response!!

i dont know what else to do, i need to be able to have html the server sends readable by 127.0.0.1:PORT

here is the code:


any help appreciated
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The server design is a bit odd. I suggest to work through the Java Networking Tutorial, especially the section Writing a Client/Server Pair.
 
Jeff Yan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in what sense is it odd?? i need some constructive critasism. the problem with that tutorial is that i do not want to implement that knock knock protocol! i want it to be able to receive a GET request and process it accordingly, either getting a requested webpage or directory / file.
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah - HTTP. That's a bit different from most other TCP/IP protocols (in that it closes the connection after the response, unless Keep-Alive is used), and the code you have accordingly more "normal". One issue that often leads to "hangs" is Don't println to a Socket (which this code does, via the "readLine" call).

A second issue is that HTTP ends lines using "\r\n" - this code uses just a newline.

Lastly, HTTP (even just GET) is a lot more complex than what this code does, but I assume you have read the relevant specification, so you know that already.
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may also want to put in a packet sniffer on your client and see how is the server response differing from an actual GET response. That may reveal if anything else is missing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic