VB winsock传输文件问题
比如我要用VB的winsock控件把"d:\a.exe"传给另外一个程序!比如服务端把"d:\a.exe"传输给客户端保存为"e:\b.exe"代码越简单越好!传送文件大...
比如我要用VB的winsock控件把"d:\a.exe"传给另外一个程序!
比如
服务端把"d:\a.exe"传输给客户端保存为"e:\b.exe"
代码越简单越好!
传送文件大小不一样! 展开
比如
服务端把"d:\a.exe"传输给客户端保存为"e:\b.exe"
代码越简单越好!
传送文件大小不一样! 展开
2个回答
展开全部
服务器代码:
Option Explicit
Private Sub Command1_Click()
Dim BytDate() As Byte
Dim FileName As String
Dim lngFile As Long
Dim i As Long
FileName = "d:\a.exe " '取得文件名及路径
lngFile = FileLen(FileName) \ 1024 '取得文件长度
Me.ProgressBar1.Min = 0
Me.ProgressBar1.Max = lngFile + 1
ProgressBar1.Value = 0
For i = 0 To lngFile
ReDim myFile(1023) As Byte '初始化数组
Open FileName For Binary As #1 '打开文件
Get #1, i * 1024 + 1, myFile '将文件写入数组
Close #1 '关闭文件
Winsock1.SendData myFile '发送
DoEvents
ProgressBar1.Value = ProgressBar1.Value + 1
Next i
If ProgressBar1.Value = ProgressBar1.Max Then MsgBox "OK"
End Sub
Private Sub Form_Load()
Winsock1.Protocol = sckTCPProtocol
Winsock1.LocalPort = 2001
Winsock1.Listen
FormCLI.Show
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> 0 Then Winsock1.Close
Winsock1.Accept requestID
End Sub
客户端代码:
Option Explicit
Private Sub Form_Load()
With Winsock1
.Protocol = sckTCPProtocol
.RemoteHost = "192.168.0.69"
.RemotePort = 2001
.Connect
End With
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Static i As Long
Dim myFile() As Byte
Dim myLong As Double
Dim myPath As String
myPath = "e:\b.exe"
ReDim myFile(bytesTotal - 1) '此处也可以是(0 To bytesTotal-1)
Winsock1.GetData myFile
Open myPath For Binary As #1 '新建文件
myLong = FileLen(myPath)
Put #1, myLong + 1, myFile '将收到的数据写入新文件中
Close #1 '关闭
End Sub
抄的。
Option Explicit
Private Sub Command1_Click()
Dim BytDate() As Byte
Dim FileName As String
Dim lngFile As Long
Dim i As Long
FileName = "d:\a.exe " '取得文件名及路径
lngFile = FileLen(FileName) \ 1024 '取得文件长度
Me.ProgressBar1.Min = 0
Me.ProgressBar1.Max = lngFile + 1
ProgressBar1.Value = 0
For i = 0 To lngFile
ReDim myFile(1023) As Byte '初始化数组
Open FileName For Binary As #1 '打开文件
Get #1, i * 1024 + 1, myFile '将文件写入数组
Close #1 '关闭文件
Winsock1.SendData myFile '发送
DoEvents
ProgressBar1.Value = ProgressBar1.Value + 1
Next i
If ProgressBar1.Value = ProgressBar1.Max Then MsgBox "OK"
End Sub
Private Sub Form_Load()
Winsock1.Protocol = sckTCPProtocol
Winsock1.LocalPort = 2001
Winsock1.Listen
FormCLI.Show
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> 0 Then Winsock1.Close
Winsock1.Accept requestID
End Sub
客户端代码:
Option Explicit
Private Sub Form_Load()
With Winsock1
.Protocol = sckTCPProtocol
.RemoteHost = "192.168.0.69"
.RemotePort = 2001
.Connect
End With
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Static i As Long
Dim myFile() As Byte
Dim myLong As Double
Dim myPath As String
myPath = "e:\b.exe"
ReDim myFile(bytesTotal - 1) '此处也可以是(0 To bytesTotal-1)
Winsock1.GetData myFile
Open myPath For Binary As #1 '新建文件
myLong = FileLen(myPath)
Put #1, myLong + 1, myFile '将收到的数据写入新文件中
Close #1 '关闭
End Sub
抄的。
展开全部
完整的winsock传输源文件已上传,请下载使用:
http://files.7lx.com/data/2010-12/2010december8th110009_1.rar
http://files.7lx.com/data/2010-12/2010december8th110009_1.rar
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |