Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTTP Server / Client

 
vinay kharad
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all.

I need to write one HTTP socket Server / client programme where in i will receive a HTTP request like ( http://sms.example.in/receivesms/Message.aspx?usr=abc&pass=xyz&msisdn=919820667597&sid=SMS&msg=test from swappy&mt=0 ) process the request and again send a HTTP request to this gateway using the HTTP Protocol Get Method like ( ttp://sms.startcorp.in/sendsms/Message.aspx?usr=abc&pass=xyz&msisdn=919820667597&sid=SMS&msg=test from swappy&mt=0 )

I need to know can i do this by jst writting simple HTTP Server / Client routine by using JAva.net 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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

While it is possible to write the server-cum-client just using the java.net 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 java.net package in turn.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This advice all sounds right on. If you're interested in writing your own HTTP server, see FitNesse.org 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic