how to make a URL conection through a seperate thread in the a client program
hi
look into the program..... this is a client progrm... which will print on the screen all the characters sent from the server program..... but..... if a character '1' is received from the server it opens a thread inputthread1 and makes a URL connection to www.myportal.com. but i am getting 14 errors in the program..... will any kind heart can look into the bug and send a reply?
thanks in advance
here is the program
import java.io.*;
import java.net.*;
public class MultimediaClient1 extends Thread
{
static Socket cs = null;
static DataInputStream theTimestream;
String theTime;
public static void main(String args[])
{
try
{
cs=new Socket("localhost",4000);
System.out.println("connected to server");
BufferedReader in=new BufferedReader(new InputStreamReader(cs.getInputStream()));
//InputThread1 st=new InputThread1(cs.getInputStream());
//st.start();
theTimestream=new DataInputStream(cs.getInputStream());
String theTime=theTimestream.readLine();
System.out.println(theTime);
if (theTime=='1'){
InputThread1 st=new InputThread1(cs.getInputStream());
st.start();
}
InputScan is=new InputScan();
is.start();
while(true)
{
String msg;
msg=in.readLine();
System.out.println(msg);
}
}
catch(Exception e){
System.out.println(e);
}
}//end main
}//end class
class InputScan extends MultimediaClient1
{
DataInputStream stdin=new DataInputStream(System.in);
public void run()
{
try
{
PrintWriter out=new PrintWriter(cs.getOutputStream(),true);
while(true)
{
String msg;
msg=stdin.readLine();
out.println(msg);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}//end class
class InputThread1 extends ServerSample1{
Socket cs;
InputStream is;
public InputThread1(InputStream is){
this.is=is;
}
public void run(){
try{
u=new URL("http://www.myportal.com");
// now turn the URLinto a database stream
try{
uc=u.openConnection();
DataInputStream theHTML =new DataInputStream(uc.getInputStream());
try{
while((thisLine=theHTML.readLine())!=null){
System.out.println(thisLine);
}
}
catch (Exception e){
System.err.println(e);
}
}
catch (Exception e){
System.err.println(e);
}
}
catch (MalformedURLException e){
System.err.println(args[0]+"is not a parseable URL");
System.err.println(e);
}
}
}