• 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

Can I still use tomcat with this Problem?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all, just a quick question. Im trying to experiment with my Java application(A class that uses ServerSocket that listens to connections) and now I want it to have a web interface (whenever someone connects, the web interface updates and shows their IP address). I was planning on deploying it to tomcat but then I realized that tomcat is only a web server( or am I wrong?) and might not be able to serve its purpose. I dont know if the ServerSocket can still exist and wait for sockets in tomcat. Now Im really stumped and dont know what technology to use. What possible technologies should I use? I really dont know what to read about so hopefully someone can point me to the right direction. Thanks very much.
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my thought on this scenario:

MYServer{

try {
int port = 2000;
ServerSocket srv = new ServerSocket(port);

// Wait for connection from client.
Socket socket = srv.accept();

//Genrate HTML
createClientHtml();

} catch (IOException e) {
}

}//class

The createClientHtml method would be responsible to create client information html at any location on your server.

Also you can save this file at your app context on tomcat server.

For example:
save html file at C:\Tomcat 6.0\webapps\myapp\clientInfo.html

and then the URL would be:

http://localhost:8080/myapp/clientInfo.html

or
you also can add this file in The optional taglib element of web.xml (deployment descriptor)

URL would be:
http://localhost:8080/myapp
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

then I realized that tomcat is only a web server( or am I wrong?) and might not be able to serve its purpose. I dont know if the ServerSocket can still exist and wait for sockets in tomcat.


Tomcat is a web server and a servlet container. It's perfectly possible to run Java code in it that opens a ServerSocket (not on the ports that Tomcat is listening for HTTP/HTTPS, obviously, but I'm sure you already knew that :-)
 
gavino ang
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:

then I realized that tomcat is only a web server( or am I wrong?) and might not be able to serve its purpose. I dont know if the ServerSocket can still exist and wait for sockets in tomcat.


Tomcat is a web server and a servlet container. It's perfectly possible to run Java code in it that opens a ServerSocket (not on the ports that Tomcat is listening for HTTP/HTTPS, obviously, but I'm sure you already knew that :-)



Oh thanks dittmer! Yeah I feel stupid now, thanks for all the answers. I originally posted this on the java beginners but it got transferred here so apologies if this was obvious. Yes I knew it can do that, I had this preconceived idea that since it works on a request/response setup, the sockets that I originally opened would die once I clicked on another page.
 
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic