发送的:
Dim myfile() As Byte
Dim position As Long
Dim FileName As String
FileName = txtaddress.Text
position = FileLen(FileName)
ReDim myfile(position - 1) As Byte
Open FileName For Binary As #1
Get #1, , myfile
Close #1
sockclient.SendData myfile
接受的:
Private lenth As Long '已经收到的数据的长度,再添加时以这个长度为依据
Private Sub sockserver_DataArrival(ByVal bytesTotal As Long)
Dim receivefile() As Byte, i As Long
ReDim receivefile(1 To bytesTotal) '次处也可以是(0 To bytesTotal-1)
sockserver.GetData receivefile, vbArray + vbByte
Open "c:\a.bmp" For Binary As #1
Put #1, lenth + 1, receivefile
Close #1
Private Sub Command1_Click()
Dim n As Long
Dim arrBytes() As Byte
Open "c:\xxxx.bmp" For Binary As 1
n = LOF(1)
ReDim arrBytes(1 To n) As Byte
Get 1, , arrBytes
Close 1
Open "c:\temp.bmp" For Binary As 1
Put 1, , arrBytes
Close 1
MsgBox "ok"