Posted By:
ajay_luthria
Posted On:
Tuesday, March 12, 2002 09:39 AM
I have a Java Client which shud invoke a Servlet within 10 seconds ie (it shud make a url connection within a time frame). If it doesnt do this within 10 seconds,it shud return back saying 'Connection Timed out' I was advised to write a Threading code. Can someone please modify this to include the threading details please ajay public class HttpHandler { private static String sURL="localhost"; static String sMessage="Hello Server..Client sending Data"; public static void main(String[] args) { sendData(sMessage);
More>>
I have a Java Client which shud invoke a Servlet within 10 seconds ie (it shud make a url connection within a time frame). If it doesnt do this within 10 seconds,it shud return back saying 'Connection Timed out'
I was advised to write a Threading code.
Can someone please modify this to include the threading details please
ajay
public class HttpHandler {
private static String
sURL="localhost";
static String sMessage="Hello
Server..Client sending Data";
public static void main(String[] args)
{
sendData(sMessage);
}
public static void sendData(String sMess)
{
HttpURLConnection hpCon=null;
String response=null;
try{
URL url=null;
String uri = "http://" + > sURL + ":8080/servlet/threads.Recieve_Http_Data";
url = new URL(uri);
hpCon=null;
hpCon = (HttpURLConnection)url.openConnection();
DataOutputStream dos = new DataOutputStream(hpCon.getOutputStream());
dos.writeUTF(sMess);
//Receive Data from server
DataInputStream dis = null;
dis = new DataInputStream(hpCon.getInputStream());
try {
response = dis.readUTF();
System.out.println("SERVER RESPONSE : " + response);
}finally
{
dos.close();
dis.close();
}
}catch(IOException e)
{
System.out.println("Error in Client " + e);
}
}
}
.
<<Less