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?
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.
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.
Joined: Nov 08, 2011
Thanks Rob, sorry if I sound a bit dumb, its all very new.
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.
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Nov 08, 2011
Thanks Tim, half the battle is understanding the different methods.