Private Sub cmdSend_Click()
'向服务器发送文件
Dim myFile() As Byte
Dim lngFile As Long '文件长度
Dim FileName As String '文件名称
Static i As Single
sockClient.Close
sockClient.Connect
Do
DoEvents
If sockClient.State = sckConnected Then
Exit Do
Else
i = i + 1
If i > 200000 Then
Dim box As String
box = MsgBox("是否放弃?", vbYesNo, "连接失败:")
If box = vbYes Then
i = 0
Exit Do
Else
i = 0
End If
End If
End If
DoEvents
Loop
lenth = 0
'检查是否与服务器连接
If sockClient.State = sckConnected Then
Private Sub sockServer_DataArrival(Index As Integer, ByVal bytesTotal As Long)
'接收文件
Static i As Long
Dim myFile() As Byte
Dim myLong As Double
Dim myPath As String
myPath = VB.App.Path & "\a.doc"
cmdC.Caption = "正在接收数据... " & bytesTotal
ReDim myFile(0 To bytesTotal - 1) '此处也可以是(0 To bytesTotal-1)
sockServer(Index).GetData myFile
i = i + 1
Open myPath For Binary As #1 '新建文件
Put #1, lenth + 1, myFile '将收到的数据写入新文件中
Close #1 '关闭
'记录文件长度
lenth = lenth + UBound(myFile) - LBound(myFile) + 1