• 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

What sort of Java to use with my Tomcat server?

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

This site kept appearing in my google quest for information so I thought I'd ask here directly.

I have spent the last few weeks figuring out how to deploy a tomcat6 server on a linux machine and it has an ajp connector set up also. Its all up and running now and I've played with some of the examples and they are all working.

What I am trying to do next is to make a standard java program to run on a client machine, not a browser based client.

I want this java program to send a simple String to the tomcat server where it will be processed and return a string.

I've looked at the sun tutorial on sockets but couldn't get it working and was told it wasn't an ideal solution. Could someone advise or link to some tutorials for something suitable?

Thanks in Advance,

Isla
 
Saloon Keeper
Posts: 7585
176
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If for some reason you're set on using Tomcat as the server, then using HTTP makes more sense than using raw TCP/IP sockets. Here's an example of how a Java desktop app might access a servlet running inside Tomcat: http://www.exampledepot.com/egs/java.net/ReadFromURL.html. The URL can contain parameters so that the servlet's response can vary according to the input it gets.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also read http://www.exampledepot.com/egs/java.net/Post.html (which is linked to from that page) for how to do a POST request instead of a GET request.
 
Isla Haper
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Guys, I'll try out the HTTP method.

But if I really really wanted to do sockets could I do it?
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends what you want to connect to. You can always implement HTTP requests with raw sockets but you really don't want to. You can connect to the AJP connector directly if you understand its communication protocol. You can have a web application start a separate server socket and connect to that. However, the simplest way remains using URL and HttpURLConnection (or a library with a higher abstraction level like Apache's HttpClient) to connect to an existing HTTP servlet or JSP page.
 
Isla Haper
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob, sorry if I sound a bit dumb, its all very new.

The functionality I want is identically to that shown in in the knock knock tutorial: http://download.oracle.com/javase/tutorial/networking/sockets/clientServer.html

Is there a tutorial showing a similar thing for HTTP?

Edit: Also seen as the client program will be a GUI run locally on the desktop will HTTP still be the right tool for the job?
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The main reason why you'd want to use the Http connection classes instead of brute-force socket communications is the extra support you'll get.

The HTTP classes use the raw sockets as their underpinning, but they automatically handle the unique requirements of the HTTP protocol. They automatically manage headers and cookies, they parse out HTTP objects and response codes, and they make it simpler to construct a POST data stream.

It really doesn't matter about the form and nature of the client. Regardless of whether the client is a stand-alone Application, an applet, a mobile app or something else entirely (including another server), you'll benefit by using the Http classes if you intend to talk to an HTTP server like Tomcat.
 
Isla Haper
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim, half the battle is understanding the different methods.
 
The moustache of a titan! The ad of a flea:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic