problem with socket......

below is the code for a client communicating with a server capable of handling multiple clients

problem is the this client sends the data and server recieves it but client is not able to read data sent by the server

but if i use awt where user request and response are handled in seperate thread it works....

publicclass dosclient1

{

publicstaticvoid main(String[] args)

{

new dosclient1();

}

Socket client;

DataInputStream dis;

DataOutputStream dout;

byte buff[]=newbyte[256];

byte buff1[]=newbyte[256];

dosclient1()

{

startclient();

}

void startclient()

{

try

{

InetAddress Server_ip=InetAddress.getByName("192.168.0.38");

int server_port=1999;

client=new Socket(Server_ip,server_port);

dis=new DataInputStream(client.getInputStream());

dout=new DataOutputStream(client.getOutputStream());

BufferedReader in =new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter Message :\t");// sending data to server

String request =in.readLine();

buff1 = request.getBytes();

dout.write(buff1);

do{// reading data sent by server

int s2=dis.read(buff);

String s=new String(buff ,0,s2);

System.out.println("\nResponse: \t"+s);

}while(true);

}

catch(Exception ex){System.out.println("Error"+ex);}

}

}

any suggestions......thanks

[2885 byte] By [BRAVOa] at [2007-11-27 8:26:18]
# 1
Do it in a separate thread then.
puckstopper31a at 2007-7-12 20:15:40 > top of Java-index,Java Essentials,Java Programming...
# 2
thanks for quick reply ...i tried that also .....not working .... can u adjust the code above.....
BRAVOa at 2007-7-12 20:15:40 > top of Java-index,Java Essentials,Java Programming...
# 3

try to Make the Current Running Thread to Sleep for some seconds and then try to read the data from the server.

buff1 = request.getBytes();

dout.write(buff1);

dout.flush();

try

{

Thread.currentThread().sleep(2000);

}

catch(Exception ex)

{

ex.printStackTrace();

}

do{// reading data sent by server

int s2=dis.read(buff);

String s=new String(buff ,0,s2);

System.out.println("\nResponse: \t"+s);

}while(true);

rajarama at 2007-7-12 20:15:40 > top of Java-index,Java Essentials,Java Programming...