我正在将图像文件从服务器套接字传输到客户端套接字,而在outstream上写入字节是我在流上写完整个字节数据后关闭流然后它工作正常但关闭套接字因此防止套接字关闭问题我没有关闭从服务器端输出,然后while循环在客户端运行无限时从输入流读取。
从
下面的服务器端代码发送文件<?php
namespace MasterBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
use Symfony\Component\Validator\Mapping\ClassMetadata;
class ChangePassword
{
private $oldPassword;
private $newPassword;
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('oldPassword', new Userpassword(array(
'message' => 'Your current password is not correct.',
)));
$metadata->addPropertyConstraint('newPassword', new Assert\NotBlank(array(
'message' => 'New password can not be blank.',
)));
$metadata->addPropertyConstraint('newPassword', new Assert\Regex(array(
'pattern' => '/^(?=.*[a-z])(?=.*\\d).{6,}$/i',
'message' => 'New password is required to be minimum 6 chars in length and to include at least one letter and one number.'
)));
}
// other setter and getter stuff.
}
客户端代码读取数据
byte buf[] = new byte[1024];
int len;
try {
while ((len = inputStream.read(buf)) != -1) {
out.write(buf, 0, len);
}
out.flush();
// out.close();
inputStream.close();
} catch (IOException e) {
Log.d(TAG, e.toString());
return false;
}
所以我应该使用任何分隔符来停止while循环,因为我理解的是,如果我不关闭服务器的outstream,所以不符合条件-1。
所以任何一个帮助将不胜感激。