CLDC and MIDP - TC65 TCP connexion
Hi, i use a TCP client on my TC65 which connect to a PC server. My code :
publicboolean initConnexionTCP(){
String openParm ="socket://" + destHost +":" + destPort+";" + connProfile;
System.out.println("Tentative de connection: " + destHost +"@" + destPort);
try{
sc = (SocketConnection) Connector.open(openParm);
System.out.println("Connection OK...");
is = sc.openInputStream();
os = sc.openOutputStream();
}catch(ConnectionNotFoundException e)
{
System.out.println("Connection Not Found");
returnfalse;
}catch (Exception e)
{
System.out.println("Connexion : " + e.getMessage() + e.getClass());
returnfalse;
}
returntrue;
}
And when i read data from server i use
is.available()
to know if data is in my buffer. TC65 example uses
while(ch != -1){
ch = is.read();
}
. But when i m waiting ch == -1 it s never appended. is.available() works but sometimes my client is waiting data from server and it waits too.
My reception function on TC65 (client) is :
public String readTCP(InputStream is)throws IOException{
int ch=0;
StringBuffer str=new StringBuffer();
while(is.available()==0);
while (is.available() > 0){
ch=is.read();
str.append((char)ch);
}
//System.out.println(str);
return str.toString();
}
Sometimes communications are ok, sometimes there is a trouble during transfer,...?
Someone knows something about that ?
Thanks !

