0

我正在尝试从 java 服务器套接字中的 php 客户端套接字读取字符串。我在 php 套接字客户端中写了两个字符串

$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)
socket_connect($this->socket, $this->host, $this->port)
$text = 'SGSA:PRINT:RECIBO';
socket_write($this->socket, $text,  strlen($text));
$text = 'Mensagem para imprimir';
socket_write($this->socket, $text,  strlen($text));

但是,当我像下面这样在 java 中阅读它时

Socket clientSocket = server.accept();
InputStream in = clientSocket.getInputStream();
String msg;
try {
   msg =  IOUtils.toString( in );
} finally {
   IOUtils.closeQuietly(in);
}

它一次读取两个字符串。

run-single:
SGSA:PRINT:RECIBOMensagem para imprimir

如何每次读取一个字符串?

4

0 回答 0