发送端:
Private Sub wskSend_DataArrival(ByVal bytesTotal As Long)
Dim bytHead As Byte
Dim LngMod As Long
Dim Buf() As Byte
Dim BufSend(MAXCHUNK - 1) As Bytei = 0
wskSend.GetData bytHead, vbByte
Select Case bytHead
Case CONHEAD '接受表头成功,则开始发送数据
If LngFileLen = 0 Then
wskSend.SendData CONEND
Else
LngMod = LngFileLen Mod MAXCHUNK - 1
If LngMod = -1 Then LngMod = MAXCHUNK - 1
ReDim Buf(LngMod)
Open txtFileName.Text For Binary Access Read As #1
Get #1, , Buf
wskSend.SendData Buf
End If
Case CONDATA
'如没结束
If Loc(1) < LngFileLen Then
Get #1, , BufSend
wskSend.SendData BufSend
Else
wskSend.SendData CONEND
End If
Case CONEND
Close #1
Status "文件发送完成!"
End Select
Private Sub sendfile()
Dim StrSend As String
Dim Buf() As Byte'发送文件头
StrSend = GetFileName(txtFileName.Text)
LngFileLen = FileLen(txtFileName.Text)
ProgressBar1.Max = LngFileLen
Buf = StrConv("a" & StrSend & "*" & LngFileLen, vbFromUnicode)
Buf(0) = CONHEAD
wskSend.SendData Buf
End SubPrivate Sub cmdSend_Click()
If txtFileName = "" Then
MsgBox "还没有选择要发送的文件...", vbCritical
Else
If frmServer.wskSend.State <> sckClosed Then
sendfile
End If
End If
End Sub
我想能够显示已经传送的字节数.谢谢
Private Sub wskSend_DataArrival(ByVal bytesTotal As Long)
Dim bytHead As Byte
Dim LngMod As Long
Dim Buf() As Byte
Dim BufSend(MAXCHUNK - 1) As Bytei = 0
wskSend.GetData bytHead, vbByte
Select Case bytHead
Case CONHEAD '接受表头成功,则开始发送数据
If LngFileLen = 0 Then
wskSend.SendData CONEND
Else
LngMod = LngFileLen Mod MAXCHUNK - 1
If LngMod = -1 Then LngMod = MAXCHUNK - 1
ReDim Buf(LngMod)
Open txtFileName.Text For Binary Access Read As #1
Get #1, , Buf
wskSend.SendData Buf
End If
Case CONDATA
'如没结束
If Loc(1) < LngFileLen Then
Get #1, , BufSend
wskSend.SendData BufSend
Else
wskSend.SendData CONEND
End If
Case CONEND
Close #1
Status "文件发送完成!"
End Select
Private Sub sendfile()
Dim StrSend As String
Dim Buf() As Byte'发送文件头
StrSend = GetFileName(txtFileName.Text)
LngFileLen = FileLen(txtFileName.Text)
ProgressBar1.Max = LngFileLen
Buf = StrConv("a" & StrSend & "*" & LngFileLen, vbFromUnicode)
Buf(0) = CONHEAD
wskSend.SendData Buf
End SubPrivate Sub cmdSend_Click()
If txtFileName = "" Then
MsgBox "还没有选择要发送的文件...", vbCritical
Else
If frmServer.wskSend.State <> sckClosed Then
sendfile
End If
End If
End Sub
我想能够显示已经传送的字节数.谢谢
用它
Private Sub Winsock1_SendProgress(ByVal bytesSent As Long, ByVal bytesRemaining As Long)End Sub不用再解释了吧