如何用MFC实现如同oicq或netmeeting方式的文件传输?

fleg 2001-03-04 08:47:00
如题!
...全文
704 34 打赏 收藏 转发到动态 举报
写回复
用AI写文章
34 条回复
切换为时间正序
请发表友善的回复…
发表回复
softarts 2001-04-24
  • 打赏
  • 举报
回复
在我的主页有一个vc写的com的例子
很早时写的
不过传输200M的文件都没有问题,你可以改进一下
http://softarts.home.chinaren.com/download/tranfile.zip
flytiger1977 2001-04-24
  • 打赏
  • 举报
回复
说来听听!
fleg 2001-04-24
  • 打赏
  • 举报
回复
我做出来了
gameboy999 2001-03-12
  • 打赏
  • 举报
回复
这我可就帮不上忙啦:)
gameboy999 2001-03-12
  • 打赏
  • 举报
回复
这我可就帮不上忙啦:)
fleg 2001-03-09
  • 打赏
  • 举报
回复
vb呀,可我不懂
gameboy999 2001-03-09
  • 打赏
  • 举报
回复
代码缺陷还比较多,没有加出错处理。。。。
该程序既做服务端,又做客户端

'Author:Dah
'Coded time:2000.11.10 //y.m.d
'Usage:transfer a file to other pcs through intranet with winsock power
Option Explicit
Dim mybyte() As Byte '发送方数组
Const filecomesMSG = "a file is coming " '有文件到来
Const RemoteIsReadyMSG = "I'm ready " '准备好了
Const FileisOverMSG = "the file is ended" '文件完毕
Const RemoteDenyMSG = "the user canceled"
Const filecountMSG = "the file lengh is"
Dim arrdata() As Byte '收到的信息
Dim filesave As Integer '保存文件的句柄
Dim filehandle As Integer '发送方文件的句柄
Dim MyLocation As Double
Dim myMSG As String '消息
Dim FileisTransfer As Boolean '文件正在传送
Dim Isendfile As Boolean '是否是本人在传送
Dim FileisOver As Boolean '文件是否已经完毕
Dim Counttime As Integer '需要传递的次数
Dim totaltime As Variant
Private Sub cmdsend_Click()
On Error GoTo errorhandle
'this is needed for correct filename
filehandle = FreeFile
If Mid(File1.Path, Len(File1.Path), 1) = "\" Then
Open File1.Path & File1.FileName For Binary Access Read As #filehandle
Else
Open File1.Path & "\" & File1.FileName For Binary Access Read As #filehandle
End If
Isendfile = True '是本人在传送
FileisOver = False '文件刚开始
cmdsend.Enabled = False
Label1.Caption = "Wait for reply..."
MsgBox ("the selected file size is " & LOF(filehandle) & " bytes")
totaltime = Int(LOF(filehandle) / 4000 + 1)
MyLocation = Loc(filehandle)
Winsock.SendData filecomesMSG & File1.FileName '发送发出文件信息
Winsock.SendData filecountMSG & totaltime
Exit Sub
errorhandle: MsgBox ("You havn't choose a file!")
End Sub

Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub

Private Sub Form_Load()
Drive1.Drive = "c:\"
Winsock.RemoteHost = "255.255.255.255"
Winsock.LocalPort = 7904
Winsock.Bind 7904
Winsockfile.RemoteHost = "255.255.255.255"
Winsockfile.LocalPort = 7905
Winsockfile.Bind 7905
FileisTransfer = False 'initialize the bool value
Isendfile = False
FileisOver = True
Counttime = 0
Label1.Caption = "Ready..."
End Sub

Private Sub Timer1_Timer()
Dim i As Integer
If LOF(filehandle) - MyLocation > 4000 Then
ReDim mybyte(0 To 4000)
Get #filehandle, , mybyte
MyLocation = Loc(filehandle)
Winsockfile.SendData mybyte
Counttime = Counttime + 1
Label1.Caption = "the select file is being transfered..." & "about " & Counttime & " / " & totaltime
Timer1.Enabled = False
Else
ReDim mybyte(0 To LOF(filehandle) - MyLocation - 1)
Get #filehandle, , mybyte
Winsockfile.SendData mybyte
FileisTransfer = False
Timer1.Enabled = False
FileisOver = True
End If

End Sub

Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
Winsock.GetData myMSG
Select Case Mid(myMSG, 1, 17)
Case filecomesMSG '这些消息发送方和接受方都可收到
'do display a form
If Not Isendfile Then '接受方处理这些事情
On Error GoTo errorhandle
CommonDialog1.FileName = Mid(myMSG, 17, Len(myMSG))
CommonDialog1.ShowSave
filesave = FreeFile
FileisTransfer = True
cmdsend.Enabled = False
Open CommonDialog1.FileName For Binary Access Write As #filesave
Winsock.SendData RemoteIsReadyMSG
Label1.Caption = "the select file is being transfered..."
End If
Case RemoteIsReadyMSG
'do begin transfer a file
'如果文件还没有结束,也就是说,只有主机才能受到
If Isendfile Then
If Not FileisOver Then
Timer1.Enabled = True
Label1.Caption = "the select file is being transfered..."
Else
Winsock.SendData FileisOverMSG
End If
End If
Case FileisOverMSG
If Not Isendfile Then '客户机处理
Close #filesave
FileisTransfer = False
Else '主机处理
Isendfile = False
Close #filehandle
End If
MsgBox ("the file is transfered successfully!") '大家一起处理
Isendfile = False
cmdsend.Enabled = True
Label1.Caption = "Ready..."
Case RemoteDenyMSG
If Isendfile Then
MsgBox ("The user canceled this transfer session!")
Isendfile = False
FileisOver = True
cmdsend.Enabled = True
Label1.Caption = "Ready..."
Close #filehandle
End If
Case filecountMSG
If Not Isendfile Then
totaltime = Mid(myMSG, 17, Len(myMSG))
End If
End Select
Exit Sub
errorhandle: Winsock.SendData RemoteDenyMSG
End Sub
Private Sub writetofile()
Put #filesave, , arrdata
End Sub

Private Sub Winsockfile_DataArrival(ByVal bytesTotal As Long)
If FileisTransfer Then
Winsockfile.GetData arrdata, vbArray + vbByte, 4001
writetofile
Winsock.SendData RemoteIsReadyMSG
Counttime = Counttime + 1
Label1.Caption = "the select file is being transfered..." & "about " & Counttime & "/" & totaltime
End If
End Sub

fleg 2001-03-06
  • 打赏
  • 举报
回复
300分,难道没有人要?
hzyem 2001-03-06
  • 打赏
  • 举报
回复
hddav(哈哈哈),那里有源码下载请指教~~~~~~!!!
hzyem 2001-03-06
  • 打赏
  • 举报
回复
gameboy999同志,能不能给你编的程序我参考一下,拜托了!!!!
hzyem 2001-03-06
  • 打赏
  • 举报
回复
gameboy999同志,能不能给你的程式我参考一下!!!拜托了
gameboy999 2001-03-06
  • 打赏
  • 举报
回复
用启停应答式来传输文件,我倒是用VB做了个,还没赶上用VC++来做呢。
fleg 2001-03-06
  • 打赏
  • 举报
回复
我一直没有找到下载的地方
hzyem 2001-03-06
  • 打赏
  • 举报
回复
搞错了,我想知道那里有源码下载!!!!!!!
呵呵!!!
hzyem 2001-03-06
  • 打赏
  • 举报
回复
我现在知道那里有源码下载,各位真的要帮帮忙!小弟真的很需要这个东西!!!
那里有这方面的书?我所看到的都写得很简单,根本满足不了我的要求,各位顺便介绍一些书来看吧!!!!!
piaoyun 2001-03-06
  • 打赏
  • 举报
回复
其实用UDP可以轻松的实现,你说的功能,可以下载几个源码,或者看看书。因为是一个很长
的话题就不多说了。
piaoyun 2001-03-06
  • 打赏
  • 举报
回复
其实用UDP可以轻松的实现,你说的功能,可以下载几个源码,或者看看书。因为是一个很长
的话题就不多说了。
hddav 2001-03-06
  • 打赏
  • 举报
回复
到处都是原程序,你不会下载一个
随风bj 2001-03-06
  • 打赏
  • 举报
回复
如果用MFC中的CSocket的话就最好在线程中进行文件传输,如果用tcp那么就可以不必校检,因为tcp是可靠的面向连接的传输方式,不过如果你害怕以外中断的话,可以事先约定每隔多少字节发送一个确认包,这样可以实现断点传输了,如果用UDP的话,那么每个包的发送和接收都要有校检,比如我发一个包,在包头有包的大小等信息,那么在我接受到包并检验收到的包的大小和包头中的一致时,便发一个确认的信息回去,这样就可以发下一个包,也可以只发缺少的包的序号(自己定义),然后对方就按照此序号发包直到得到结束信息
vcyzq 2001-03-06
  • 打赏
  • 举报
回复
关注!!
加载更多回复(14)
NetMeeting For Windows7系统补丁 因为MSASN动态链接库的冲突,Windows7不再支持Netmeeting,鉴于Vista和Windows7内核的同源性。特别修改了一下Netmeeting内核程序,使得Windows7能够正常运行Netmeeting。 首先:安装NetMeeting3.0.2(Netmeeting-kb927853-x86-enu.msi)。安装方法和Vista相似。 因为NetMeeting的安装程序要检测Windows版本,所以有可能会报告不兼容,不过没关系,照常运行安装就是了。安装过程中会报告MSASN1.dll的某个函数点无法定位。 现在安装过的NetMeeting还不能运行,需要进行破解(即将Cracks目录下文件拷贝到C:\Program Files\NetMeeting\下并替换源文件。) 接下来就重新启动 尝试下,可以运行NetMeeting了 (*^__^*) 嘻嘻…… Cracks目录下各种文件属性说明: callcont.dll NetMeeting拨号程序,这个程序会检测Windows内核版本。 conf.exe NetMeeting主执行程序,这个是从XP下分离的,用来破解共享桌面. confold.exe NetMeeting主执行程序,这个是从NetMeeting3.01单独发行版分离的,功能同上,如果你使用Home版而且Conf.exe运行失败了,可以尝试用它。 dcap32.dllNetMeeting食品捕获程序,这个程序经过汉化。 MsAsn2.dll 破解的转接文件,有了它才能正常的在Windows7/Vista下运行本补丁。 MST120.dll 接口文件,被修改重定向MSASN1.dll到MSASN2.dll NMAS.dll NetMeeting内核文件,这个程序经过汉化. NMCHAT.dll NetMeeting聊天室程序,这个程序经过汉化。 NMCom.dll NetMeeting文件接口程序,被修改重定向MSASN1.dll到MSASN2.dll NMFT.dll NetMeeting文件传输程序,这个程序经过汉化。 NMoldwb.dll 旧版电子白板程序,这个程序经过汉化。 NMwb.dll 新版电子白板程序,这个程序经过汉化,被修改重定向MSASN1.dll到MSASN2.dll。
因为MSASN动态链接库的冲突,Windows7不再支持Netmeeting,鉴于Vista和Windows7内核的同源性。特别修改了一下Netmeeting内核程序,使得Windows7能够正常运行Netmeeting。 首先:安装NetMeeting3.0.2(Netmeeting-kb927853-x86-enu.msi)。安装方法和Vista相似。 因为NetMeeting的安装程序要检测Windows版本,所以有可能会报告不兼容,不过没关系,照常运行安装就是了。安装过程中会报告MSASN1.dll的某个函数点无法定位。 现在安装过的NetMeeting还不能运行,需要进行破解(即将Cracks目录下文件拷贝到C:\Program Files\NetMeeting\下并替换源文件。) 接下来就重新启动 尝试下,可以运行NetMeeting了 (*^__^*) 嘻嘻…… Cracks目录下各种文件属性说明: callcont.dll NetMeeting拨号程序,这个程序会检测Windows内核版本。 conf.exe NetMeeting主执行程序,这个是从XP下分离的,用来破解共享桌面. confold.exe NetMeeting主执行程序,这个是从NetMeeting3.01单独发行版分离的,功能同上,如果你使用Home版而且Conf.exe运行失败了,可以尝试用它。 dcap32.dllNetMeeting食品捕获程序,这个程序经过汉化。 MsAsn2.dll 破解的转接文件,有了它才能正常的在Windows7/Vista下运行本补丁。 MST120.dll 接口文件,被修改重定向MSASN1.dll到MSASN2.dll NMAS.dll NetMeeting内核文件,这个程序经过汉化. NMCHAT.dll NetMeeting聊天室程序,这个程序经过汉化。 NMCom.dll NetMeeting文件接口程序,被修改重定向MSASN1.dll到MSASN2.dll NMFT.dll NetMeeting文件传输程序,这个程序经过汉化。 NMoldwb.dll 旧版电子白板程序,这个程序经过汉化。 NMwb.dll 新版电子白板程序,这个程序经过汉化,被修改重定向MSASN1.dll到MSASN2.dll。 VVNET补充 上面的方法在我的WIN764位机器不太好使, 增加了nm30.exe(NetMeeting安装包) 在win7_64机器先安装nm30.exe,再把cracks下文件复制到netmeeting安装目录下覆盖。

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧