首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    局域网文件传输软件[通俗易懂]

    大家好,又见面了,我是你们的朋友全栈君。在公司实习了一个周,虽然很累,但也感觉有所得,此次项目是做一个局域网两台计算机之间的文件传输。我用的主要控件为winsock控件,用其TCP协议。至于用此控件连接两台计算机书上都有介绍,我主要介绍一下我传送文件的思想和方法: 首先,将要传送的文件分成指定大小的N个包,大小不能超过8K因为TCP每次最多发送8K数据,最后一个包可能会小于其它包。然后在每个包加个包头,因为接收端需要通过包头知道传送过来的是数据还是路径(因为发送端指定存放路径),接收端收到数据后必须返回确认到发送端,这样才能循环发送,但一定要有最后的终止,不然会死循环。我的主要发送和接收代码如下: 发送端收到数据后产生的事件 Private Sub WskCli_DataArrival(ByVal bytesTotal As Long) Dim FIT As Boolean, OVER As Boolean, xx As Byte WskCli.GetData FIT If Number < BagNum Then If FIT = True Then ‘接收端已收到上一个数据包 If v <> 0 Then ‘传送速率受限制 Dim ss As Long ss = 0 Do Until (Number * 1024 <= v * ss) ‘传送速率过大则等待 ss = CLng((Time – timeInt) * 3600 * 24) Loop End If Send_File ‘调用发送文件数据包过程 End If Number = Number + 1 ‘计数 ProgressBar1.Value = Number * 20 / BagNum ‘刷新进度条的进度 El** *x = 2 WskCli.SendData xx ‘发送传送完毕的信息给接收端 Close 1 Label1.Caption = “发送完毕!” OVER = True Number = 0 ‘传送完后置计数Number=0 End If If OVER = True Then ‘传送完之后的处理 Drive1.Enabled = True Dir1.Enabled = True File1.Enabled = True CmdSend.Enabled = True Exit Sub End If End Sub send_file是自定义的一个发送过程: Private Sub Send_File() Dim i As Long ‘循环变量 If Number <= BagNum – 1 Then ReDim Buff(1 To BagSize) As Byte ‘定义缓冲区 ReDim TempBuff(0 To BagSize) As Byte Get 1, , Buff TempBuff(0) = 1 ‘设置包头为1代表文件数据 For i = 1 To BagSize TempBuff(i) = Buff(i) Next WskCli.SendData TempBuff Else ‘传送最后一个数据包 n = filelength – Seek(1) + 1 ‘得到最后一个包的大小 If n > 0 Then ReDim Buff(0 To n) As Byte ReDim TempBuff(0 To n) As Byte TempBuff(0) = 1 ‘设置包头为1代表文件数据 Get 1, , Buff For i = 1 To n TempBuff(i) = Buff(i – 1)

    03

    两位数活多位乘法的计算编程

    Private Sub Command1_Click() Dim M As String Dim N As String M = Trim(Text1.Text) N = Trim(Text2.Text) Dim Number1() As Byte Dim Number2() As Byte ReDim Number1(Len(M)) ReDim Number2(Len(N)) Dim index As Byte For index = 1 To Len(M) Step 1 Number1(index) = Mid(M, index, 1) Next index For index = 1 To Len(N) Step 1 Number2(index) = Mid(N, index, 1) Next index Dim Result() As Byte ReDim Result(Len(M) + Len(N)) Dim MCarry As Byte Dim ACarry As Byte Dim Remainder As Integer Dim i As Integer, j As Integer Dim Mtemp As Integer, Atemp As Integer For i = Len(N) To 1 Step -1 For j = Len(M) To 1 Step -1 Mtemp = Number1(j) * Number2(i) + MCarry MCarry = Mtemp \ 10 Remainder = Mtemp Mod 10 Atemp = Remainder + Result(i + j) + ACarry ACarry = Atemp \ 10 Result(i + j) = Atemp Mod 10 Next j Result(i) = MCarry + ACarry MCarry = 0 ACarry = 0 Next i Dim Mstr As String For index = 1 To Len(N) + Len(M) Mstr = Mstr & Str(Result(index)) Next Label3.Caption = Mstr End Sub

    02
    领券