Doesn't loop a while(true) !!!
I made an Client Chat applet, but for some reason it doesn't do the read/write part to the socket that happens while(true)!!!
Well, actually it doesn't even load the screen! I mean the layout...
As you can see, wrote some System.out.println() to see where it gets stuck, and gets up to "7" and stops - it writes "7" only once and it's in a while(true)!!!
Please help me...
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
import java.net.*;
publicclass mainextends Applet{
boolean sent =false;
String senttxt =null;
TextArea maintext =new TextArea(17,50);
TextField sendtext =new TextField(40);
Button send =new Button("Send!");
publicvoid init(){
setLayout(new FlowLayout());
add(maintext);
add(sendtext);
add(send);
maintext.setEditable(false);
cmain();
}
catch(Exception e){
System.out.println(7);
}*/
}
public main(){
}
/**Construct the applet*/
privatevoid cmain(){
Socket echoSocket =null;
PrintWriter out =null;
BufferedReader in =null;
System.out.println(1);
try{
echoSocket =new Socket("127.0.0.1", 4445);
System.out.println(2);
out =new PrintWriter(echoSocket.getOutputStream(),true);
System.out.println(3);
in =new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
System.out.println(4);
}catch (UnknownHostException e){
maintext.append("Couldn't find server - maybe offline");
System.out.println("Couldn't find server - maybe offline");
}catch (IOException e){
maintext.append("There was a problem connecting server");
System.out.println("There was a problem connecting server");
}
System.out.println(5);
BufferedReader stdIn =new BufferedReader(new StringReader("User Connected!\n"));
System.out.println(6);
try{
while (true){
System.out.println(7);
if(sent){
stdIn =new BufferedReader(new StringReader(senttxt+"\n"));
try{ out.println(stdIn.readLine());}catch (IOException e){}
senttxt =null;
sent=false;
System.out.println(8);
}
try{ maintext.append(in.readLine());}catch (IOException e){ System.out.println(9);}
}
}finally{
System.out.println(8);
out.close();
try{ in.close();}catch (IOException e){}
try{ stdIn.close();}catch (IOException e){}
try{ echoSocket.close();}catch (IOException e){}
}
}
publicboolean action(Event evt, Object arg){
if(evt.targetinstanceof Button || evt.targetinstanceof TextField){
senttxt = sendtext.getText();
sendtext.setText("");
sent=true;
returntrue;
}
returnfalse;
}
}

