我想单简的用一个API
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
'
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function
Private Sub Command1_Click()
DownloadFile "http://nic.ysu.edu.cn/jswd/jswd/images/xlogo.gif", "c:\aa.gif"
Private Sub wsListen_DataArrival(Index As Integer, ByVal bytesTotal As Long)
--改这里
If Not GotHeader(index-1) Then
Dim Dat As String
wsListen(Index).GetData Dat$, vbString
ReDim Preserve ftRcv(0 To Index)
If Left(Dat$, 4) = "FILE" Then
Dim FirstPos As Long, SecondPos As Long
FirstPos = InStr(6, Dat, ":")
SecondPos = InStr(FirstPos + 1, Dat, ":")
With ftRcv(Index)
.FileName = Mid(Dat, 6, (FirstPos - 6))
.FileSize = CDbl(Mid(Dat, FirstPos + 1, (SecondPos - FirstPos) - 1))
'.Comment = Right(Dat, 200)
'.From = wsReceive.RemoteHostIP
'.frmRcOpt.Prepare MyID
.Destination = "E:\Receive\" & Mid(Dat, 6, (FirstPos - 6)) 'save the file to
wsListen(Index).SendData "ACCEPT"
GotHeader = True
End With
End If
Else
'**************************************
If FileNum = 0 Then
FileNum = FreeFile
On Error Resume Next
If FileLen(ftRcv(Index).Destination) > 0 Then Kill ftRcv(Index).Destination
Open ftRcv(Index).Destination For Binary As #FileNum
End If
Dim DepoT() As Long
Dim GotDat() As Byte
'Dim Hash As Stringhi,
ByteSec = ByteSec + bytesTotal
Receivedbyt = Receivedbyt + bytesTotal
ReDim GotDat(0 To bytesTotal - 1)
wsListen(Index).GetData GotDat, vbArray + vbByte
Put #FileNum, , GotDat
Label2.Caption = "有文件正在传送..."
If Receivedbyt = ftRcv(Index).FileSize Then
Close FileNum
Complete = True
wsListen(Index).Close
Label2.Caption = ""
End If
End If
End Sub
你的GotHeader 是1个bool类型的值吧,这样改,把它改成数组
dim GotHeader() as bool
Private Sub wsListen_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
intMax = intMax + 1
Load wsListen(intMax)
wsListen(intMax).LocalPort = 0
wsListen(intMax).Accept requestID
--这里加
redim Preserve GotHeader(intMax-2)
只有horsefly() ( ) 信誉:105 老兄切中问题的实质,
freedomjim(老头) ( ) 信誉:100 老兄的程序我早已实现谢谢!。
zgvslch(烟花离落) ( ) 信誉:100 老兄的的长篇大论可以帮初学者!。
我要的是服务器端同时处理各客户端发来的大量数据,
Private Sub Form_Load()
wsListen(0).LocalPort = FT_USE_PORT
wsListen(0).Listen
End Sub
Private Sub wsListen_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
intMax = intMax + 1
Load wsListen(intMax)
wsListen(intMax).LocalPort = 0
wsListen(intMax).Accept requestID
End If
End Sub
Private Sub wsListen_DataArrival(Index As Integer, ByVal bytesTotal As Long)
If Not GotHeader Then
Dim Dat As String
wsListen(Index).GetData Dat$, vbString
ReDim Preserve ftRcv(0 To Index)
If Left(Dat$, 4) = "FILE" Then
Dim FirstPos As Long, SecondPos As Long
FirstPos = InStr(6, Dat, ":")
SecondPos = InStr(FirstPos + 1, Dat, ":")
With ftRcv(Index)
.FileName = Mid(Dat, 6, (FirstPos - 6))
.FileSize = CDbl(Mid(Dat, FirstPos + 1, (SecondPos - FirstPos) - 1))
'.Comment = Right(Dat, 200)
'.From = wsReceive.RemoteHostIP
'.frmRcOpt.Prepare MyID
.Destination = "E:\Receive\" & Mid(Dat, 6, (FirstPos - 6)) 'save the file to
wsListen(Index).SendData "ACCEPT"
GotHeader = True
End With
End If
Else
'**************************************
If FileNum = 0 Then
FileNum = FreeFile
On Error Resume Next
If FileLen(ftRcv(Index).Destination) > 0 Then Kill ftRcv(Index).Destination
Open ftRcv(Index).Destination For Binary As #FileNum
End If
Dim DepoT() As Long
Dim GotDat() As Byte
'Dim Hash As Stringhi,
ByteSec = ByteSec + bytesTotal
Receivedbyt = Receivedbyt + bytesTotal
ReDim GotDat(0 To bytesTotal - 1)
wsListen(Index).GetData GotDat, vbArray + vbByte
Put #FileNum, , GotDat
Label2.Caption = "有文件正在传送..."
If Receivedbyt = ftRcv(Index).FileSize Then
Close FileNum
Complete = True
wsListen(Index).Close
Label2.Caption = ""
End If
End If
End Sub
'我已写了一个理论上能传任意大小文件,
'分为服务端和客户端但是当有多个客户端同时
'上传时就有问题了不知道你们是如何处理并行上传的
这是主要的接收代码但不能同时处理多个客户并行上传