• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread Challenge

 
Karthic Gunasekaran
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am trying to create a Network Topology simulation,wherein I need to write/read as part of the requirement.

The rough sketch of the program is like below.

Class Writer implements Runnable
{
pubic void write(Socket socket)
{
Thread t1 = new Thread();
t1.start();
Reader reader = new Reader();
reader.read(socket);
}

public void run()
{
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
dos.writeUTF("DATA1");
dos.writeChars("009 From Socket No: "+temp.toString());
dos.flush();

PrintWriter a = new PrintWriter(socket.getOutputStream());
a.write("DATA2");
a.println("DATA3");
a.flush();
}
}

class Reader implements Runnable
{
public void read(Socket socket){
Thread t1 = new Thread();
t1.start();
}

public void run(){

DataInputStream dis = new DataInputStream(socket.getInputStream());
InputStream inputFromSocket = socket.getInputStream();
BufferedReader streamReader = new BufferedReader(new InputStreamReader(inputFromSocket));
String strTemp1 = streamReader.readLine();
System.out.println("gk"+dis.available());
while(true){
if(strTemp!=null)
{
System.out.println("DATA from I/P Stream"+strTemp);
}
if(dis.available!=null){
System.out.println("DATA from Datat I/P Stream"+dis.available());
}
}
}
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what is your question?
 
Karthic Gunasekaran
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question is that,even after I write to the stream,am not able to read anything from the Input Stream.Absolutely nothing is getting printed.
[ October 01, 2006: Message edited by: Karthic Gunasekaran ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the program finish without printing anything, or does it hang?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Karthic]: Absolutely nothing is getting printed.

Ask yourself - why should anything get printed? What part of the program should be printing something? Is that part being run? (Hint: no.) More specifically: what it is the relationship between the Thread objects you create, and the Runnable instances you create? (Hint: no relationship at all.)
 
Karthic Gunasekaran
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks folks!Appreciate your help!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!