Hi guys,

I have to make an application, which connects to a
servlet over HTTP . I have
to make the application interface in Swing. On
clicking a button I have
to generate cookies and send these cookies to the
servlet. The communication
between the application and the servlet has to be
through sockets... The application
also has to add its own headers to the request ...

The servlet will accept the cookies from the
application and will then
send back an acknowledgement to the application along
with its own
cookies...the servlet will read the headers sent by
the client application
and send an acknowledgement to the application ...

both the application and the servlet are running on
the same machine , and
i will be using servletrunner....

maybe i can use the URLConnection class and make the
connection to the servlet...
but how do i create and send the cookies ?? and is
making a connecton through the
URLConnection class the same thing as using sockets ??

The following is the code, that i THINK may work ...

This is the code for the application client:

**************
try{
URL url = new URL(http://localhost:servlet/myservlet);
URLConnection urlcon = url.openConnection();
urlcon.setAllowUserInteraction(true);
urlcon.setDoInput(true);
urlcon.setDoOutput(true);
//urlcon.setRequestProperty("cookiename","cookievalue");
System.out.println("calling the servlet...");
urlcon.connect();
}catch(MalformedURLException
murle){System.out.println("MalformedURLException
:"+murle);}}
  catrch(IOException ioe){System.out.println("IO
Excpeiton :"+ioe);}

// write stuff to servlet
PrintWriter toServlet = new
PrintWriter(urlcon.getOutputStream());
toServlet.print(cookiename);
toServlet.print(cookievalue);
toServlet.flush();

//read stuff from servlet
BufferedReader fromServlet = new BufferedReader(new
InputStreamReader(urlcon.getInputStream()));
String input;
StringBuffer sb;
while(input=fromServlet.readLine() != null)
{
  sb.append(input);
}

****************

In the above there are 2 ways that i can send the
cookie to the servlet, one is by
sending it as "RequestProperty" header and the other
is by opening streams ...

In the above code snippet i am getting the following
exception :


Calling the servlet...
IO exceptionjava.net.ConnectException: Connection
refused: no further information


Will i have to use Socket objects for making the
connection ?? With both the servlet and
the application having server sockets and client
sockets for communication ?? Please correct
me where i am going wrong ...

Thanks a lot for yr patience and time ... hope to get
some ideas/pointers on this

Regards,

Ritin Mathur

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to