bom, valeu ter tentado, consegui diminuir o tamanho dos dados cerca de 4 vezes, usando socket tcp, ai vai um pouco de codigo
servidor, em php
<?php
// don't timeout
set_time_limit (0);
$host = "192.168.0.118";
$port = 9000;
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
$result = socket_listen($socket, SOMAXCONN) or die("Could not set up socket listener\n");
echo "Waiting for connections...\n\n";
do {
$spawn = socket_accept($socket) or die("Could not accept incoming connection\n");
echo "Received connection request\n";
//aguarda a solicitacao do usuario
$input = socket_read($spawn, 2048) or die("Could not read input\n");
echo "Solicitacao: $input\n";
//responde a solicitacao do usuario
socket_write($spawn, $input , strlen ($input)) or die("Could not write output\n");
echo "Responde solicitacao: " . trim($input) . "\n";
socket_close($spawn);//fecha conexao
echo "servidor fechou\n-------------\n";
} while (true);
socket_close($socket);
?>
cliente em php
<?php
$host="192.168.0.118";
$port = 9000;
$fp = fsockopen ($host, $port, $errno, $errstr);
if (!$fp) {
$result = "Error: could not open socket connection";
}
else {
//solicita algo no servidor
fputs ($fp, "quero agua");
//obtem a resposta
echo fgets ($fp, 2048);
fclose ($fp);
}
?>
cliente em java, j2me
SocketConnection connection = null;
OutputStream output = null;
InputStream in = null;
try {
connection = (SocketConnection) Connector.open("socket://192.168.0.118:9000");
output = connection.openOutputStream();
in = connection.openInputStream();
//solicita algo no servidor
output.write(string1.getBytes());
output.flush();
//--
//obtem a resposta
int ch;
while( ( ch = in.read() ) != -1 ) {
System.out.print((char)ch);
}
//--
this.main.destroyApp(false);
this.main.notifyDestroyed();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(in != null) {
in.close();
}
if(output != null) {
output.close();
}
if(connection != null) {
connection.close();
}
} catch(Exception e) {
e.printStackTrace();
}
}
o servidor funciona como HTTP, recebe uma solicitacao, responde e fecha a conexao, cada vez q o cliente quer algo repete o processo.
antes um simples login gerava aproximadamente 1200 bytes, agora gera em torno de 300 bytes. não testei com UDP, mas pra mim ta bom. valeu.