最近刚开始学C#的流,不知道怎么用Socket传送文件,知道把文件做成文件流什么的,自己也写了一个小程序,但是运行的时候报错。想看一个具体的实现的例子~~~有这方面代码的希望能给我看看,谢谢!!!我的邮箱是[email protected]

解决方案 »

  1.   

    http://jiezhi.cnblogs.com/archive/2005/08/15/215419.html
      

  2.   

    http://www.chjl.cn/Article/Read.aspx?ArticleID=1736
    http://www.it023.com/software/develop/donet/2004-04-12/1081758641d14122.html
    http://www.mscenter.edu.cn/laputa/article/2004-8/0/13/8093.xml
      

  3.   

    创建一个套接字,打开一个监听端口,然后用networkstream来传就可以了。
      

  4.   

    TcpClient tcpClient = new TcpClient();
    // Uses the GetStream public method to return the NetworkStream.
    try{
        NetworkStream networkStream = tcpClient.GetStream();
        if(networkStream.CanWrite){
            Byte[] sendBytes = Encoding.ASCII.GetBytes("Is anybody there?");
            networkStream.Write(sendBytes, 0, sendBytes.Length);
        }
        else{
            Console.WriteLine("You cannot write data to this stream.");
            tcpClient.Close();
            return;
        }
        if(networkStream.CanRead){
         
          // Reads NetworkStream into a byte buffer.
          byte[] bytes = new byte[tcpClient.ReceiveBufferSize];
          // Read can return anything from 0 to numBytesToRead. 
          // This method blocks until at least one byte is read.
          networkStream.Read(bytes, 0, (int) tcpClient.ReceiveBufferSize);
                 
         // Returns the data received from the host to the console.
         string returndata = Encoding.ASCII.GetString(bytes);
         Console.WriteLine("This is what the host returned to you: " + returndata);
        }
        else{
             Console.WriteLine("You cannot read data from this stream.");
             tcpClient.Close();
             return;
        }
      }
    catch (Exception e ) {
                  Console.WriteLine(e.ToString());
           }
      

  5.   

    可以把文件做成FileStream,然后用NetworkStream传