1.用BufferedWriter封装的流对象在写入后,如果不FLUSH的话,是否对方端会接收到?是否一定要FLUSH?
2.用BufferedReader封装的套接字流再read的时候,在对方什么的条件下会触发读操作从阻塞状态转为开始读取?怎么判断对方已经写入完该报文?对方写完后一般流会有什么状态来判断对方已经写完?谢谢!
以上为C与JAVA之间通信!谢谢!

解决方案 »

  1.   

    1、不 flush 常常不能发送出最后的一部分内容,因此 flush 是必须的,因为你不能依赖于侥幸。
    2、read 时本身就已经处于阻塞状态,只有当读满缓冲区或读到文件尾时才会退出阻塞状态。返回 -1 表示已经读取了全部内容。
      

  2.   

    第一个问题:推荐使用,不用的话有潜在的一些问题。
    第二个问题:用ready方法,用法如下。
    ready
    public boolean ready()
                  throws IOException
    Tell whether this stream is ready to be read. A buffered character stream is ready if the buffer is not empty, or if the underlying character stream is ready. Overrides:
    ready in class Reader
    Returns:
    True if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block. 
    Throws: 
    IOException - If an I/O error occurs
      

  3.   

    我用了READY做判断,但是其实里面可以读到东西的,但是READY是返回FALSE!
      

  4.   

    应该是没有的,
    要么就是对方关闭,肯定发完(不过这样做不好)还有就是java 1.4后有NIO里的socket可以判断现在socket能读还是能写,自己去看看吧