• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet-Application communication

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi guys!

i'm doing a project which the server is supposed to communicate both with applets and application as clients. i got no problem with the applet side.
The servlet is supposed to listen to the application/client and talk to the database.
SO, can i use Sockets for communication between my java application and the Servlet? or give me another approach.

tnx in advance!
[ July 05, 2007: Message edited by: anteneh mamo ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, welcome to the ranch!

Yes, your Java client can use sockets to call a servlet. But the standard libraries provide some other classes to make things much easier. Look at URL and HttpURLConnection. These handle all the HTTP headers going both ways for you. The Sun Networking Tutorial works through some examples.

How is your applet calling the servlet? You should be able to use the very same code in both clients, no?
[ July 05, 2007: Message edited by: Stan James ]
 
anteneh mamo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wow! thanks James, you really helped me out. you know using HttpURLConnection,i was able to talk to my servlet.
for your question: my applet calls my servlet for the retrieval of some data from the database and the servlet ,after talking to the database ,responds. I've not used the same code for my application and applet due to the behaviour of the project.
What i want to ask you now is that: i am supposed to create a chat server process on my servlet(found on a centralized server) and one client is from my java application and the other client is from the applet.
java application <...>servlet<...>applet
plus my chat server(on my servlet) is supposed to hold multiple clients from both sides at a time. How do i do that? i'm confused a bit.
you were really helpful.
thank you.
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad to hear you're making progress. I'm still curious about how your applet talks to the servlet. What does that code look like?

Building a chat server seems to be a common educational exercise. I guess your choices are holding an open socket connection on the server for each client, or just holding an address for each client. With the former, you can wind up holding an excessive number of open connections. With the latter you have to connect, send, disconnect to broadcast a message to all clients, which can be rather slow with lots of clients.

Have you thought about how you'd like to handle all that?
 
anteneh mamo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks james!
well,my applet has got many functionality: it talks to my servlet by continous requests(using loops).
1)my applet somehow as i told you has to chat with the application client on the far end via the Servlet.
2)it has to continously request the servlets for any updates on the database found on the centralized server.
the application is responsible for continous updates of the database and hence whenever there is change in db,the servlet has to respond immediately.
About your latest answer,i don't like to use the sockets for the chat server because the application side and applet side use different protocols.
So, if you have any suggestion about the chat, you are welcome!
Thank-you
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic