I am designing a chat application using sockets. this is the code for reading data from server. It compiles just fine but the thread only runs only once. please help me out.
public void reader() {
Thread read=new Thread(){
public void run(){
try {
while(true) {
if(in.readLine()!=null) {
System.out.println("Recived Message: "+ in.readLine());
}
}
}catch(Exception e){}
}
};
read.setPriority(10);
read.start();
}
Ok I tried this code and it doesnt work as well
public void reader()
{
Thread u=new Thread()
{
public void run()
{
try {
while(true)
{
System.out.println("ssss");
if(input.readLine()!=null)
{
String message=input.readLine();
System.out.println("SERVER:"+message);
}
else{
Thread.sleep(1);
}
}
}
catch (IOException e)
e.printStackTrace();
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
};
try{
u.start();
}catch(Exception e){}
}
And the output i get is sss just once. but i have a while loop that is always true. why doesnt ir run infinitely?