• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

How to send response from a server to a Swing client

 
Ranch Hand
Posts: 30
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I want a response to be send back to the client (Swing application) from the Server (Web application) after all the process of authentication is done on the server side.

The scenario is that I had send the username & password from the swing based login form to the server (AuthenticateServlet.java) and here am doing the authentication for the user to let him login to the swing based application based on the response generated (succes or failure) at the server side.

Can any one help me what are the different ways to achieve this.

Thanks in advance.

K.Anutosh
[ September 30, 2008: Message edited by: Anutosh Swamy ]
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the URL and HttpURLConnection APIs.

You're gonna find some method like: setDoInput, setDoOutout, connect, getResponseMessage() and so on...

Long time I do not use these APIs, but they work fine
 
Anutosh Swamy
Ranch Hand
Posts: 30
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jair,

See I'd already opened an URL like this at client side

BufferedReader httpbr=null;
String url = "http://localhost:8080/MyApp/loginClient?uid="+user_name+"&pid="+password;

URL opr1_url=new URL(url);
httpbr = new BufferedReader(new InputStreamReader(opr1_url.openStream()));

And from server side I had generated a respose (success or failure).

If failure I need to send two parameters "failure" and "message for the same"

If success I need to send one paramerter "success".

How sholud I send this from server to client and read the same at client side.
 
Jair Rillo Junior
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the servlet, you can use the response object, like in Web application.

In Swing, you can use the getResponseMessage() method (or anything like this, because long time I do not use those APIs).

Certainly in the javadoc or google you'll find more information
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See this for examples of the client side, especially #135 and #136.

The server side would just be a regular servlet, so you'd use the HttpServletResponse like you would for a browser client (but you wouldn't create HTML, obviously).
 
Anutosh Swamy
Ranch Hand
Posts: 30
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jair
Thanks Ulf

This will definitely solve my issue.
 
knowledge is the difference between drudgery and strategic action -- tiny ad
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic