vb Winsocket如何传送非文本文件?

来源:百度知道 编辑:UC知道 时间:2024/05/15 16:07:27
我用服务器端:发送文件 客户端接收文件
关键代码:服务器
Private Sub Socket_DataArrival(Index As Integer, ByVal bytesTotal As Long
......................................
Socket(Index).GetData sltemData
Case "_Y_D" '------------------------------传送图片
SendFile Index, App.Path & "\131083.gif" ‘SendFile定义过程
Socket(Index).SendData "_Y_F"
Case "_Y_E"
case else
........下面是 SendFile 过程的说明
Private Sub SendFile(Index As Integer, SrcPath As String)
Dim BufFile As String '---文件缓冲区
Dim LnFile As Long '-------文件长度
Dim nLoop As Long
Dim nRemain As Long
Dim Cn As Long

On Error GoTo GLocal:
LnFile = FileLen(SrcPath)
If LnFile > 8192 Then
nLoop = Fix(LnFile / 8192)
nRemain = LnFile Mod 8192
Else
nLoop = 0
nRemain = LnFile
End If

If LnFile =

发送部分:
Open "C:\1.gif" For Binary As #1
ReDim b(1 To LOF(1))
Get #1, , b
Close #1
Winsock1.SendData b

接收部分:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim b() As Byte
ReDim b(1 To bytesTotal) '这句可以不要
Winsock1.GetData b, vbByte
Open "C:\1.gif" For Binary As #1
Put #1, , b
Close #1
End Sub

我的空间里有我网盘的地址 里面有个mail.rar

你找有best的那个版本的 那个就有这个功能!~