This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
The server design is a bit odd. I suggest to work through the Java Networking Tutorial, especially the section Writing a Client/Server Pair.
Joined: Nov 05, 2009
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.
Joined: Oct 14, 2008
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.