Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

socket output writing problem

 
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
 
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.
 
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.
 
I'm sure glad that he's gone. Now I can read this tiny ad in peace!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic