在收到数据后通知发送线程关闭输出流不就行了吗。

解决方案 »

  1.   

    不是,可能是同一时刻利用“临界资源”的问题:(
    可能加上互斥锁就能解决了
    一个读的时候锁上,没有读到再打开,等待!
    一个写的时候锁上,不写了再打开!不知道这样对不对!而且我不知道这段程序怎么写(你倒我扶:))
    有高人能给我写几行代码吗?
    谢谢了!
      

  2.   

    private byte[] buffer = new buffer[10240];...
    in read thead
    while (!terminated) {
    if (buffer.length + 1024 > 10240) {
      buffer.notify();
      buffer.wait(1000);
    } else {
      byte[] tempBuf = new byte[1024]
      int len = outStream.read(tempBuffer...);
      synchronized(buffer) {
       System.arrayCopy(buffer, buffer.length, tempBuf, 0, len);
       buffer.notify();
      }
    }...
    in write thread
    while (!terminated) {
    if (buffer.length == 0) {
      buffer.notify();
      buffer.wait(1000);
    } else {
      byte[] tempBuf = new byte[1024]
      synchronized(buffer) {
       sendData();
       buffer.notify();
      }
    }