• 大小: 0.31M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-04-23
  • 语言: C#
  • 标签: 安全  通信  加密  

资源简介


资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Text;

using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;


namespace SocketsTest
{
    public class TransferFiles
    {
        //public TransferFiles()   
        //{   
        //    //   
        //    // TODO: 在此处添加构造函数逻辑   
        //    //   
        //}   
  
  
  
        public static int SendData(Socket s byte[] data)   
        {   
            int total = 0;   
            int size = data.Length;   
            int dataleft = size;   
            int sent;   
  
            while (total < size)   
            {   
                sent = s.Send(data total dataleft SocketFlags.None);   
                total += sent;   
                dataleft -= sent;   
            }   
  
            return total;   
        }   
  
        public static byte[] ReceiveData(Socket s int size)   
        {   
            int total = 0;   
            int dataleft = size;   
            byte[] data = new byte[size];   
            int recv;   
            while (total < size)   
            {   
                recv = s.Receive(data total dataleft SocketFlags.None);   
                if (recv == 0)   
                {   
                    data = null;   
                    break;   
                }   
  
                total += recv;   
                dataleft -= recv;   
            }   
            return data;   
        }   
  
        public static int SendVarData(Socket s byte[] data)   
        {   
            int total = 0;   
            int size = data.Length;   
            int dataleft = size;   
            int sent;   
            byte[] datasize = new byte[4];   
            datasize = BitConverter.GetBytes(size);   
            sent = s.Send(datasize);   
  
            while (total < size)   
            {   
                sent = s.Send(data total dataleft SocketFlags.None);   
                total += sent;   
                dataleft -= sent;   
            }   
  
            return total;   
        }   
  
        public static byte[] ReceiveVarData(Socket s)   
        {   
            int total = 0;   
            int recv;   
            byte[] datasize = new byte[4];   
            recv = s.Receive(datasize 0 4 SocketFlags.None);   
            int size = BitConverter.ToInt32(datasize 0);   
            int dataleft = size;   
            byte[] data = new byte[size];   
            while (total < size)   
            {   
                recv = s.Receive(data total dataleft SocketFlags.None);   
                if (recv == 0)   
                {   
                    data = null;   
                    break;   
                }   
                total += recv;   
                dataleft -= recv;   
            }   
            return data;   
        }   
    }   
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2021-01-13 22:08  C#p2p\
     目录           0  2021-01-13 12:12  C#p2p\.vs\
     目录           0  2021-01-13 12:12  C#p2p\.vs\SocketsTest\
     目录           0  2021-01-13 21:49  C#p2p\.vs\SocketsTest\v16\
     文件       72192  2021-01-15 12:17  C#p2p\.vs\SocketsTest\v16\.suo
     目录           0  2021-01-13 12:12  C#p2p\Backup\
     目录           0  2021-01-13 12:12  C#p2p\Backup\SocketsTest\
     文件         923  2009-12-21 19:04  C#p2p\Backup\SocketsTest.sln
     文件        2971  2014-01-12 18:53  C#p2p\Backup\SocketsTest\FileClientSocket.cs
     文件        9859  2014-01-12 20:36  C#p2p\Backup\SocketsTest\Form1.cs
     文件       13336  2014-01-12 18:42  C#p2p\Backup\SocketsTest\Form1.Designer.cs
     文件        6387  2014-01-12 18:42  C#p2p\Backup\SocketsTest\Form1.resx
     文件        4993  2014-01-12 22:39  C#p2p\Backup\SocketsTest\Form2.cs
     文件        3378  2014-01-12 18:49  C#p2p\Backup\SocketsTest\Form2.Designer.cs
     文件        5814  2014-01-12 18:49  C#p2p\Backup\SocketsTest\Form2.resx
     文件        5944  2014-01-12 19:48  C#p2p\Backup\SocketsTest\Form3.cs
     文件       12745  2014-01-12 19:31  C#p2p\Backup\SocketsTest\Form3.Designer.cs
     文件        5814  2014-01-12 19:31  C#p2p\Backup\SocketsTest\Form3.resx
     文件         492  2009-12-21 19:04  C#p2p\Backup\SocketsTest\Program.cs
     目录           0  2021-01-13 12:12  C#p2p\Backup\SocketsTest\Properties\
     文件        1354  2009-12-21 19:04  C#p2p\Backup\SocketsTest\Properties\AssemblyInfo.cs
     文件        2872  2009-12-21 19:04  C#p2p\Backup\SocketsTest\Properties\Resources.Designer.cs
     文件        5612  2009-12-21 19:04  C#p2p\Backup\SocketsTest\Properties\Resources.resx
     文件        1096  2009-12-21 19:04  C#p2p\Backup\SocketsTest\Properties\Settings.Designer.cs
     文件         249  2009-12-21 19:04  C#p2p\Backup\SocketsTest\Properties\Settings.settings
     文件        4572  2014-01-12 18:52  C#p2p\Backup\SocketsTest\SocketsTest.csproj
     目录           0  2021-01-15 11:58  C#p2p\SocketsTest\
     文件        1139  2021-01-13 12:12  C#p2p\SocketsTest.sln
     文件       26112  2014-01-12 22:40  C#p2p\SocketsTest.suo
     目录           0  2021-01-15 07:58  C#p2p\SocketsTest\bin\
     目录           0  2021-01-14 22:22  C#p2p\SocketsTest\bin\Debug\
............此处省略48个文件信息

评论

共有 条评论