我需要将来自套接字的传入数据获取到 ByteBuffer 中,但我不知道该怎么做。我是这个领域的新手,因此不确定最好的开始方式。我发现了以下内容,但这不是我想要的,因为它可以获取数据,但我需要将我的所有数据都放在字节缓冲区中以用于其他目的。
ServerSocket welcomeSocket = new ServerSocket(Integer.parseInt(ibmPort));
while (true) {
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
clientSentence = inFromClient.readLine();
System.out.println("Received: " + clientSentence);
setRequestDataFromCT(clientSentence);
capitalizedSentence = clientSentence.toUpperCase() + '\n';
outToClient.writeBytes(capitalizedSentence);
}