|
-
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);
}
}
}
Similar Threads
-
By Mike Mitchell in forum .NET
Replies: 60
Last Post: 09-13-2002, 05:41 PM
-
By Gwyn Carwardine in forum .NET
Replies: 0
Last Post: 04-29-2002, 10:01 PM
-
Replies: 0
Last Post: 12-09-2001, 11:45 AM
-
By Kevin Chien in forum Java
Replies: 3
Last Post: 09-12-2000, 05:17 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks