我正在将SocketChannel
Java 类用于客户端/服务器应用程序。我可以发送和检索数据。但如果我的数据包含'\n'
,那么我不会读取正确的数据。例如
sending data = "Hi dear"
receiving data = "Hi dear"
sending data = "Hi dear\n\n i am fine"
receiving data = "Hi dear"
sending data = "Hi dear\\n\\n i am fine"
receiving data = "Hi dear\n\n i am fine"
ByteBuffer byteBuffer = ByteBuffer.allocate(BUFSIZE);
int nbytes = socketChannel.getChannel().read(byteBuffer);
我正在使用 US-ASCII 解码。我怎样才能克服这种类型的问题?
谢谢,迪帕克