Byte stream send/receive problem...any help?

Hi all,

I ve got the following client (applet) & server (application) and I am trying to tranfer some data between them, but strange things happen...!

For example some times the packet comes double (e.g. "Athan;Athan;" instead of "Athan;") or other times comes half! (e.g. "Atha" instead of "Athan;") I cannot understand what is going wrong! Please have a look to my code. Here is a part of it:

Server:

i = new DataInputStream(s.getInputStream());

while(startSession) //always true

{

while (i.available()<=1){};

{

str=new StringBuffer();

byte temp[]=new byte[600]; //600 is the maximum request packet size

int len=0;

len=i.read( temp );

for (int i=0;i<len;i++)

{

str.append((char)temp);

}

System.out.println(""+str.toString()+"len:"+str.length());

Client:

out = new DataOutputStream(soc.getOutputStream());

public void send(String s)

{

for (int i=0;i<s.length();i++)

{

try{

out.write((int).charAt(i));

}

catch (IOException e){}

}

I am almost sure that the problem is on the server side, since the client is sending correctly the packet.

Thanx in advance,

Athan>

[1302 byte] By [athan00] at [2007-9-26 1:23:20]
# 1
you try to send messages or files?
Dnw at 2007-6-29 1:01:41 > top of Java-index,Archived Forums,Java Programming...
# 2
I'm trying to send a message. Actually I'm trying to send a string but before I send it I try to convert it in a byte format
athan00 at 2007-6-29 1:01:41 > top of Java-index,Archived Forums,Java Programming...