aspose file tools*
The moose likes Servlets and the fly likes how to keep a java servlet running in the background? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to keep a java servlet running in the background?" Watch "how to keep a java servlet running in the background?" New topic
Author

how to keep a java servlet running in the background?

vaibhav more
Greenhorn

Joined: Mar 31, 2010
Posts: 10
Hi all!!! I am working on a project in which i need to built a j2ee application that gives sms services. In this application i need to write a servlet ahich contnuously runs n background listening to the port that is connected to the mobile. after a message is recieved the event should be notified to the servlet and the servlet should respond by sending the appropriate reply to that mobile number.
My first problem is how do i keep the servlet running in the background once i have started my web application.....


Vebster:-)
Nothing is "I M Possible"
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

A Servlet is the wrong technology to choose. Why do you think it needs to be a Servlet?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42262
    
  64
That's not what servlets are for - they follow the HTTP request/response mechanism.

If you want to handle some other protocol or port, start a separate thread (in a ServletContextListener) that handles the connection.


Ping & DNS - my free Android networking tools app
vaibhav more
Greenhorn

Joined: Mar 31, 2010
Posts: 10
actually my mobile is connected to com8 port . and i need to be notified when a sms comes so that i can reply it.
I am using at commands for it.
as the application is in j2ee, i need to write a servlet for that purpose. this servlet wil be the part f my whole website.
I am driven nuts, am not able to resolve the problem
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

why don't you write a listener that calls the servlet when request comes in?


My Blog SCJP 5 SCWCD 5
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42262
    
  64
as the application is in j2ee, i need to write a servlet for that purpose.

Servlets are for HTTP, not for communication with serial or parallel devices. You can still do what you want to do in your JEE application - just not as a servlet.
vaibhav more
Greenhorn

Joined: Mar 31, 2010
Posts: 10
Himanshu Gupta wrote:why don't you write a listener that calls the servlet when request comes in?

How to write such a port listener?
Is it possible that the listener will continuously run in background and then notify on receiving the sms. I have already written a servlet that sends an sms
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

Well.. while writing previous reply I did not know thatyou want to listen to a particular port.. I thought you are working on a web application
May be http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.htmlcan be helpful.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42262
    
  64
Is it possible that the listener will continuously run in background and then notify on receiving the sms.

Are you certain that an SMS sent by the mobile would go out to the COM port? I'd think that it goes out over the air.
vaibhav more
Greenhorn

Joined: Mar 31, 2010
Posts: 10
Himanshu Gupta wrote:Well.. while writing previous reply I did not know thatyou want to listen to a particular port.. I thought you are working on a web application
May be http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.htmlcan be helpful.


Ya thanks himanshu. i read the tutorial. i know the socket programming. I am developing the web application only.
actually my mobile is connected to port com8. a web application is there that gives sms services. i have used mobile to send messages and receive messages.
The mobile is interfaced with com8 port.
I want a jee application that will hear that port and transfer the sms recieved to "SendSms" servlet which will further respond to the request.
If i use the local java program i wont be able to continue with my web application.
vaibhav more
Greenhorn

Joined: Mar 31, 2010
Posts: 10
Ulf Dittmer wrote:
Is it possible that the listener will continuously run in background and then notify on receiving the sms.

Are you certain that an SMS sent by the mobile would go out to the COM port? I'd think that it goes out over the air.


Actually, a mobile is connected to the port. It is used both for sending as well as replying for the sms.

This is the logic for reading the sms from the port....




I need to run this code to be run continuously in the background or atlleast invoked when some message is received.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Have a look a java.util.Timer.
 
Don't get me started about those stupid light bulbs.
 
subject: how to keep a java servlet running in the background?