我正在向服務器發送字符串,並且在服務器端通過緩衝區迭代時獲取ASCCII字符。我如何發送字符串在服務器上以十六進制形式接收它?在服務器上以十六進制接收數據?
代碼
String message;
String result;
String aString = "#2016011400000060.00#010104#004500##";
// String aString = "###";
BufferedReader inFromUser = new BufferedReader(new StringReader(aString));
Socket clientSocket = new Socket("localhost", 1000);
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
message = inFromUser.readLine();
outToServer.writeBytes(message + '\n');
result = inFromServer.readLine();
System.out.println(result);
clientSocket.close();
你得到你所發送的內容。不清楚你在問什麼。 – EJP
你如何在服務器上閱讀它?爲什麼期望在原始套接字上使用十六進制而不是普通字節? – Andreas