tomcat - Do I need servlets for server-side Java programming? -


i need program small server handle requests android application. (the user sends number server, server math on numbers received each user - average, let's - , returns it).

i've read simple introduction oracle (http://docs.oracle.com/javase/tutorial/networking/sockets/clientserver.html).

it explains how leave server listening on specific door. normal java, no special application needed (such tomcat).

i know people use 'servlets' (with tomcat) accomplish kind of thing. why that? advantages? can't program sample server 1 described in simple tutorial, , leave running on computer?

i wanna understand better overall scenario. =)

using socket simple. @ first.

you create server class, have bind port , away go.

the first hurdle hit, covered in comments, multi-threading. simple producer/consumer pattern solve in no time.

the next problem hit protocol.

  • who talks first?

  • how respond?

  • how deal invalid request?

  • what happens if stream collapses during request?

  • do open new socket each request or client hold onto socket , write multiple requests?

  • maybe want sort of non-blocking io?

this http comes in, protocol communicating on tcp/ip (actually on anything, use bits of paper , bike). defines answers above questions (and many more).

so, run webserver (tomcat, glassfish) , deals raw sockets , sending right information.

a servlet abstraction, when tomcat has connection , has negotiated compression, encryption etc pass request onto servlet.

the servlet doesn't have worry raw socket, reads request , writes response.

it's worth pointing out http isn't protocol, it's 1 happens used web-browsing. , 1 used web-servers.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -