gpt4 book ai didi

java - TCP 套接字上的 Ascii

转载 作者:行者123 更新时间:2023-12-02 08:02:46 24 4
gpt4 key购买 nike

任何人都可以给我一个通过 TCP 发送 Ascii 消息的示例吗?(在网上找不到示例)

谢谢

射线。

最佳答案

Here's an example写入和读取回显服务器。

简化摘录:

    Socket echoSocket = null;
PrintWriter out = null;
BufferedReader in = null;

try {
echoSocket = new Socket("taranis", 7);
out = new PrintWriter(echoSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(
echoSocket.getInputStream()));
} catch (UnknownHostException e) {
System.err.println("Don't know about host: taranis.");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for "
+ "the connection to: taranis.");
System.exit(1);
}

BufferedReader stdIn = new BufferedReader(
new InputStreamReader(System.in));
String userInput;

while ((userInput = stdIn.readLine()) != null) {
out.println(userInput);
System.out.println("echo: " + in.readLine());
}

关于java - TCP 套接字上的 Ascii,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4773846/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com