Socket programming inside a servlet acting as server, is it a good solution to start a sort of server pushing environment?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I wouldn’t do socket programming from within a servlet; you’re likely to have all kinds of problems if the socket outlives the Request which initiates it.
Take a look at the cometd project. Comet is a technology for doing HTTP-push (basically, you hold an HTTP connection open for an arbitrarily long time, and the server pushes events down to the client as they occur, rather than waiting for the client to poll). You need a web server which will scale to support a large number of mostly-idle connections, but that’s not hard these days, and the cometd project has a number of implementations available for download. You could use theirs, or just take a look at it for inspiration if you want to build your own.