my dog learned polymorphism
The moose likes Servlets and the fly likes HTTP Server / Client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HTTP Server / Client" Watch "HTTP Server / Client" New topic

HTTP Server / Client

vinay kharad

Joined: Apr 20, 2006
Posts: 1
Dear all.

I need to write one HTTP socket Server / client programme where in i will receive a HTTP request like ( from swappy&mt=0 ) process the request and again send a HTTP request to this gateway using the HTTP Protocol Get Method like ( ttp:// from swappy&mt=0 )

I need to know can i do this by jst writting simple HTTP Server / Client routine by using package. Or do i essentially need to use any Web Server (Tomcat) to receive the request from gateway and send request. here it has to be both Server and Client.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Welcome to JavaRanch.

While it is possible to write the server-cum-client just using the package, why reinvent the wheel? It would be much easier to use Tomcat (or some other servlet engine) as the server, and have that make an HTTP request using the package in turn.
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
Strictly you don't need to use a ready made HTTP server (I have written a few special-purpose ones in the past). You can find example server source code pretty easily

Making an HTTP request as a client might even be more difficult. Personally I often use HTTPUnit for this, mainly because I'm familiar with it.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
I agree with Frank. Writing is simple HTTP request processor is quite easy. Sun supplied a good one in one of internal undocumented packages, but for some reason withdrew it recently. Creation of HTTP client is a bit more work, but httpurlconnection is working in most cases. Writing your own server can be even preferable because you can control keep-alive in better your app specific way.

Tough in space?, <a href="" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="" target="_blank" rel="nofollow">Check it here.</a><br /><a href="" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
This advice all sounds right on. If you're interested in writing your own HTTP server, see for another neat example. The code is about 10% as big as the HTTP stuff I wrote for myself. Pretty slick.

Some of the code I read to learn how to do this was peppered with comments like "obsolete version of obscure browser xyz sends an extra newline here" which made it clear it would not be easy to write a robust HTTP server to expose to the world at large. My own is supported only for captive users in my company on standard IE6 configurations and a few of us using FireFox.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: HTTP Server / Client
It's not a secret anymore!