gpt4 book ai didi

java - 读/写Java套接字流时的澄清

转载 作者:行者123 更新时间:2023-12-03 12:03:51 26 4
gpt4 key购买 nike

我在Java套接字编程中有几个问题。

  • 在读取客户端套接字中的输入流时,如果抛出IO异常;那么我们是否需要重新连接服务器套接字/再次初始化客户端套接字?
  • 如果我们关闭输出流,它将关闭客户端套接字吗?
  • 如果从输入流中读取的消息与我们期望的不同,则在客户端套接字中使用
  • ;我们有什么标准来处理吗?
  • 最佳答案

    while reading the inputstream in client socket, if it throws IO exception; then do we need to reconnect the server socket/ reintialize the client socket again?



    是的,除非它是读取操作上的 SocketTimeoutException

    if we close the output stream, will it closes the client socket?



    是的。

    in client socket, if the message read from the inputstream is different as what we expected; do we have any standard to handle this?



    否。如果该消息完全无法识别,则您可能需要切断连接。如果是已识别的消息但顺序不正确,则可能是编程错误,也可能是您在设计时没有想到的情况。解决方案:现在考虑一下。

    关于java - 读/写Java套接字流时的澄清,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43437011/

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