Qkxx
Qkxx

Reputation: 29

HTTP Client-Server resquest response

I am trying to write a simple client-server application in Java using HTTP request/response. I would like the client to be a desktop program which sends (posts) a request to a server. The server is a web page which will be hosted on Apache Tomcat server. The server must be able to read the information and display it on the browser and must be able to respond to the client with a status code 200. I am using eclipse and Apache tomcat server. I have so far tried various resources, but all I could find is a client which could request response from an already existing web server. Could someone please give me an example or some insight on how to make the client request the our own server which runs on the local machine.

Upvotes: 0

Views: 178

Answers (1)

Aung Myo Linn
Aung Myo Linn

Reputation: 2890

Good question, though in your case, I won't recommend you implement a simple HTTP request/response approach as you will end up implementing a timer, heartbeat or Comet. You might wanna try javax or jetty WebSocket API. All you need is to create three parts:

  • a websocket.server
  • a websocket.client (desktop application)
  • a javascript websocket client (browser agent)

Your server and both clients will become full-duplex via onMessage and send events.

Here's an example which I believe is a bit relevant one. https://dzone.com/articles/sample-java-web-socket-client

Upvotes: 1

Related Questions