java接收端程序用的是readLine吧?

解决方案 »

  1.   

    对啊,是用的readLine。有何问题?
      

  2.   

    readLine工作原理是等在那里直到input有了一个回车或者换行才返回整个字符串的,这个函数是阻断式的。
      

  3.   

    那我在接收二进制文件时用的read为什么还是阻断?
      

  4.   

    怎样实现的,我现正需要这样的东东,用java  很好实现,但怎样用vb 来怎样实现(我对VB 不是很懂), 能否给一份VB的代码, 不慎感谢!我的email: 
    [email protected]
      

  5.   

    Winsockserver.SendData "sample_image.gif" & Chr(10)
    mg_filename = "e:\sample_image.gif"
    da = FileLen(mg_filename)
    If da = vbNullString Then
       Exit Sub
    End IfOpen mg_filename For Binary As #1For i = 0 To da \ 4096
        If da < 4096 Then
           ReDim myfile(1 To da) As Byte
        Else
           ReDim myfile(1 To 4096) As Byte
           da = da - 4096
        End If    Get #1, i * 4096 + 1, myfile    Winsockserver.SendData myfile
        'Winsockserver.SendData Chr(10)
        For j = 1 To 5000
            DoEvents
        Next jNext i
        
    Close #1
      

  6.   

    那用java怎么实现呀?用什么来读数据流呢?
      

  7.   

    你的java是如何读数据的呢?满足什么条件才不读取数据呢?
      

  8.   

    import java.net.*;
    import java.io.*;
    import java.util.*;public class sink {
      public static void main(String[] args) throws IOException
      {
        String mg_filename=new String();    Socket client = new Socket("makegame", 8888);
        System.out.println("Connect ...");
        System.out.println(new Date());
        BufferedReader mg_filein=new BufferedReader(new InputStreamReader(client.getInputStream()));    System.out.println("Reading ...");     mg_filename=mg_filein.readLine();
         System.out.println(mg_filename+":"+Integer.toString(mg_filename.length()));     BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(mg_filename),4096);
         BufferedInputStream in = new BufferedInputStream(client.getInputStream(),4096);
         byte[] c = new byte[4096];     int count = in.read(c);
         while (count != -1)
     {
              out.write(c,0,count);
              count = in.read(c);
             }
        System.out.println("Reading down.");
        System.out.println(new Date());
        in.close();
        out.close();
        client.close();
        System.out.println("Closed.");
          }}
      

  9.   

    我也遇到这个情况,我发现程序运行到
    while (count != -1)
     {
              out.write(c,0,count);
              count = in.read(c);
             }
     就不会往下执行了,因为in.read(c)是阻塞的。
      

  10.   

    除非连接断开的时候in.read(c)才返回-1.