• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Generic servlet which can listen on a socket

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am very new to the servlet concept. I am trying to write an application which takes input (Non SIP non HTTP) on a socket & then converts it into SIP. Here is a scenario ....

1. My application will be listening on a socket say for example 7080 and will receive message.( Message simply contains To and from user name)
2. A generic servlet will get invoked which will construct a sip message using the caller-callee information sent in a simple string. ( I am not looking for any parsing to be done by container).
3. That generic servlet will then invoke a sip servlet.

Can somebody help me in designing this application.













abcd.JPG
[Thumbnail for abcd.JPG]
 
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to Java Ranch !!!

you can write a Generic Servlet which will have 3 methods

a. init()
b. service()
c. destroy()

In init() method, you can write code which listens to port 7080
When ever a message is recieved on port 7080, control goes to service() method where you can construct sip message using the caller-callee information. Then control can be forwarded to SIPServlet with required information
In destroy() method, you can discontinue listening to port 7080 (closing the socket)


~ abhay
 
Ankit Bhandari
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Abhay Agarwal wrote:Welcome to Java Ranch !!!

you can write a Generic Servlet which will have 3 methods

a. init()
b. service()
c. destroy()

In init() method, you can write code which listens to port 7080
When ever a message is recieved on port 7080, control goes to service() method where you can construct sip message using the caller-callee information. Then control can be forwarded to SIPServlet with required information
In destroy() method, you can discontinue listening to port 7080 (closing the socket)


~ abhay




Thanks a lot Abhay !!!

I have one doubt regarding the approach you suggested. As per specification of jsr289 and container manual, it says we should not spawn a new thread from servlet, as container manages the thread pool ( Please Correct me if i am wrong.
1. Will it be okay to spawn a thread from init ?
2. The thread that gets spawned through init() is container thread or an independent thread ( How can i verify this by looking at thread signature ...).


Thanks you
Regards,
Ankit Bhandari
 
Ankit Bhandari
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Abhay,

I have one doubt regarding invoking service method. As you said, "When ever a message is received on port 7080, control goes to service() method " . Can you please help us in doing this. I am not able to invoke service from there.

Thank you
Regards,
Ankit Bhandari
 
Ranch Hand
Posts: 171
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
service() -Dispatches client requests to the protected service method. There's no need to override this method.
 
Saloon Keeper
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not convinced that tackling this issue within the confines of the Servlet API is the right approach. The GenericServlet/HttpServlet distinction makes it sound as if every protocol could be handled simply by extending GenericServlet, whereas the API is actually geared very much towards request/response protocols like HTTP. Your problem sounds like it would be better handled by directly listening on a socket, and then making SIP requests from within that socket server.
 
Ankit Bhandari
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim,
Thanks for your reply. As you suggested, will it be okay to invoke a listening socket from container. Or i can make container to listen on a socket and deliver raw buffer to some servlet.


Thank you
Regards,
Ankit Bhandari
 
Tim Moores
Saloon Keeper
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you can open a ServerSocket from within a servlet container. Or you can create your own server that is independent of it. Not sure what you mean by "deliver to some servlet". Your server process would not be a servlet, no matter whether it runs inside the servlet container, or outside of it.
 
Ankit Bhandari
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Tim.
 
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic