Forums Register Login

Thread Challenge

+Pie Number of slices to send: Send
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());
}
}
}
+Pie Number of slices to send: Send
So what is your question?
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
Does the program finish without printing anything, or does it hang?
+Pie Number of slices to send: Send
[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.)
+Pie Number of slices to send: Send
Thanks folks!Appreciate your help!
I'm so happy! And I wish to make this tiny ad happy too:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 604 times.
Similar Threads
Why is my connection reset on this test program?
problem in simple chat application.
readUTF locking up GUI
threads concurrency problem
BufferedReader .readLine() is not seeing end of file
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:59:24.