如何从php套接字客户端在java服务器套接字中每次读取一个字符串

时间:2013-04-22 02:12:21

标签: java php sockets

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

中写了两个字符串
$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

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

0 个答案:

没有答案