Ciao, allora, è un paio di ore che ho programmato per permettere al client di inviare pacchetti massimi di 10KB.
Anche se arrivano spezzati il server li ricostruisce....
In più ho implementato la funzione per decidere se usare o meno la compressione zlib...
CMQ sia, gestire un server è più complicato di quanto immaginassi:
codice:
sub buffering {
my $utente=shift;
my $buf=shift;
my $temp;
if($utente->{dim}>0) {
$utente->{buf}.=$buf;
if (length $buf == $utente->{dim}) {
$temp=$utente->{buf};
$utente->{buf}="";
$utente->{dim}=-1;
return uncompress($utente->{buf}) if ($utente->{compresso});
return $utente->{buf};
}
if (length $utente->{buf} > 10240 || length $utente->{buf} > $utente->{dim}) {
$utente->{dim}=-1;
$utente->{buf}="";
}
return undef;
}
return undef if (substr($buf,0,2) ne "\x87\x89");
unpack("C",substr($buf,2,1))>1 ? return undef : ($utente->{compresso}=unpack("C",substr $buf,2,1 ));
unpack("S",substr($buf,3,2))>10240 ? return undef : ($utente->{dim}=unpack("S",substr $buf,3,2));
if ($utente->{dim}==length($buf)-5) {
$utente->{dim}=-1;
print "l'ho inviato subito senza comprimerlo? ".$utente->{compresso}."\n";
return uncompress(substr($buf,5,length($buf)-5)) if $utente->{compresso};
return substr($buf,5,length($buf)-5);
}
$utente->{buf}=substr($buf,5,length($buf)-5);
print "Pacchetto suddiviso in più parti\n";
return undef;
}
Grazie