Problem in socket

Guys I need your help ?br>Scenario is this I had open a socket connection from servlet ( sun application server ) ?and connection made successfully..

Even I can write through this socket connection ?but when I try to read data from this open connection its always return available byte zero.\

So I am not able read any data. ?Do I need to make some setting on application server level for retrieving data ?

Code that is like this ?.

void startClient(){

Socket client = null;

InputStream in = null;

OutputStream out = null;

try {

client = new Socket("10.208.10.44",2345);

in = client.getInputStream();

out = client.getOutputStream();

boolean read_status = true;

while(read_status == true){

int avl = in.available();

System.out.println("number of bytes avialable is " +avl );

if(avl > 0){

byte[] data = new byte[avl];

int read_amount = in.read(data);

System.out.println("number ob byte read " +read_amount );

System.out.println(" data read is " + new String(data) );

}

else if(avl == 0){

Thread.sleep(2000);

}

else{

read_status = false;

}

}

} catch (Exception e) {

e.printStackTrace();

}

}

Guys Please Reply ? Thanks

[1333 byte] By [Ravindra_shuklaa] at [2007-10-3 4:27:17]
# 1

Well you're in the wrong forum, but:

> boolean read_status = true;

> while(read_status == true){

Delete the first line and change the second to while (true)

>int avl = in.available();

> System.out.println("number of bytes avialable

> ialable is " +avl );

> if(avl > 0){

Delete the above lines

>byte[] data = new byte[avl];

Change this to byte[] data = new byte[8192];

> int read_amount = in.read(data);

After this add if (read_amount < 0) break;

> System.out.println("number ob byte read "

> read " +read_amount );

> System.out.println(" data read is " + new

> + new String(data) );

This is all OK except for the last line which should be new String(data,0,read_amount).

>else if(avl == 0){

>Thread.sleep(2000);

>}

>else{

> read_status = false;

>}

> }

Delete all this, it's just a waste of time. read() blocks anyway.

ejpa at 2007-7-14 22:30:03 > top of Java-index,Core,Core APIs...