java socket 服务端实现将16进制数组变成Ascll码发送出去的完整代码
时间: 2023-04-10 07:00:56 浏览: 124
以下是Java Socket服务端实现将16进制数组变成ASCII码发送出去的完整代码:
```java
import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = new ServerSocket(8888);
System.out.println("Server started.");
while (true) {
Socket socket = serverSocket.accept();
System.out.println("Client connected.");
byte[] hexArray = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64}; // 16进制数组
String asciiString = new String(hexArray, "ASCII"); // 将16进制数组转换成ASCII码字符串
OutputStream outputStream = socket.getOutputStream();
outputStream.write(asciiString.getBytes()); // 发送ASCII码字符串
socket.close();
System.out.println("Client disconnected.");
}
}
}
```
请注意,这只是一个示例代码,实际应用中需要根据具体需求进行修改。
阅读全文