Sunday, 15 September 2013

apache - How do you send a 503 error page directly with Java sockets -



apache - How do you send a 503 error page directly with Java sockets -

i'm trying build simple server in java.

basically have far serversocket listening on port. working well. want implement servers ability respond requests. begin want reply bad requests 503.

the best thought have doing so, using bufferedwriter like

... out.write("http/1.0 503 bad request\r\n"); out.write("date: mon, 23 jun 2014 23:59:59 gmt\r\n"); out.write("server: apache/1.3.2\r\n"); ...

however seems error-prone. also, i've looked @ apache's httpcomponents examples , have built-in class httpresponses using them complicated , involves whole infrastructure built around them.

does have suggestions on how homecoming httpresponses in java?

sending 503 clients plain server socket not thought unless both client , server agree implement http protocol on both side.

when dealing plain socket connections, working on tcp layer of networking stack. using application logic @ tcp layer not thought , hence application layer protocols exist such http.

and unless there no real need of writing fresh implementation of protocol such http don't so. seek utilize existing implementations such servlets in java.

hope helps.

java apache sockets httpresponse apache-httpcomponents

No comments:

Post a Comment