>>> send Private Sub Command1_Click() Winsock1.RemoteHost = "127.0.0.1" Winsock1.RemotePort = 9988 Winsock1.Connect End SubPrivate Sub Command2_Click() Dim FileArray() As Byte Open "E:\OICQ\qq.exe" For Binary As #1 '我们测试一个>8K的文件 'ReDim FileArray(lof(1)) 'at first you should tell the client the correct file length ReDim FileArray(1720390) 'at first you should tell the client the correct file length Get #1, , FileArray Winsock1.SendData FileArray Close #1 End Sub >>> ReceiveDim FileCount As LongPrivate Sub Form_Load() Winsock1.LocalPort = 9988 Winsock1.Listen End SubPrivate Sub Winsock1_Close() Winsock1.Close Label1.Caption = "Connect Close" End SubPrivate Sub Winsock1_ConnectionRequest(ByVal requestID As Long) Winsock1.Close Winsock1.Accept requestID Label1.Caption = "Connect OK"'Open File for write Open "e:\oicq\qq2.exe" For Binary As #1 End SubPrivate Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim getArray() As Byte ReDim getArray(bytesTotal) Winsock1.GetData getArrayFileCount = FileCount + bytesTotal Label1.Caption = CStr(Int(FileCount * 100 / 1720390)) + " %" '1720390 is the file length. At first you should try to get the correct file length If FileCount <= 1720390 + 1 Then '1720390 is the file length. At first you should try to get the correct file length '1720390+1 是为了文件的实际长度和数组的序号匹配 Put #1, , getArray Else Close #1 Label1.Caption = "Receive OK!" End If End Sub
>>> send Private Sub Command1_Click()
Winsock1.RemoteHost = "127.0.0.1"
Winsock1.RemotePort = 9988
Winsock1.Connect
End SubPrivate Sub Command2_Click()
Dim FileArray() As Byte
Open "E:\OICQ\qq.exe" For Binary As #1 '我们测试一个>8K的文件
'ReDim FileArray(lof(1)) 'at first you should tell the client the correct file length
ReDim FileArray(1720390) 'at first you should tell the client the correct file length
Get #1, , FileArray
Winsock1.SendData FileArray
Close #1
End Sub
>>> ReceiveDim FileCount As LongPrivate Sub Form_Load()
Winsock1.LocalPort = 9988
Winsock1.Listen
End SubPrivate Sub Winsock1_Close()
Winsock1.Close
Label1.Caption = "Connect Close"
End SubPrivate Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
Label1.Caption = "Connect OK"'Open File for write
Open "e:\oicq\qq2.exe" For Binary As #1
End SubPrivate Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim getArray() As Byte
ReDim getArray(bytesTotal)
Winsock1.GetData getArrayFileCount = FileCount + bytesTotal
Label1.Caption = CStr(Int(FileCount * 100 / 1720390)) + " %" '1720390 is the file length. At first you should try to get the correct file length
If FileCount <= 1720390 + 1 Then
'1720390 is the file length. At first you should try to get the correct file length
'1720390+1 是为了文件的实际长度和数组的序号匹配
Put #1, , getArray
Else
Close #1
Label1.Caption = "Receive OK!"
End If
End Sub