• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

What sort of Java to use with my Tomcat server?  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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: 5486
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 21745
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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: 21745
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Bartender
Posts: 20745
124
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks Tim, half the battle is understanding the different methods.
 
This tiny ad is wafer thin:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!