Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to keep a java servlet running in the background?

 
vaibhav more
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.....
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Servlet is the wrong technology to choose. Why do you think it needs to be a Servlet?
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
vaibhav more
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why don't you write a listener that calls the servlet when request comes in?
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look a java.util.Timer.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic