| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 943 人关注过本帖
标题:[求助]怎样在局域网中实现文件传输?
只看楼主 加入收藏
lkjkf
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2005-4-21
收藏
 问题点数:0 回复次数:2 
[求助]怎样在局域网中实现文件传输?
大家好!我想做一个在局域网中实现文件传输的程序。2个客户端的程序通过服务器能够相互传输文件,除了使用Ftp这种方法外,还有什么方法能够实现?因为Ftp太麻烦了,有没有简单一点的?谢谢啦!
搜索更多相关主题的帖子: 局域网中 服务器 文件 传输 
2006-11-20 15:06
ncqingchuan
Rank: 1
等 级:新手上路
帖 子:58
专家分:0
注 册:2006-8-8
收藏
得分:0 

给你一个简单的事例
服务器端

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
TcpServer.Stop()
System.Environment.Exit(System.Environment.ExitCode)
End Sub


Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ServerIp As IPHostEntry = Dns.GetHostByAddress("127.0.0.1")
TcpServer = New TcpListener(ServerIp.AddressList(0), 6000)
TcpServer.Start()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim FS As New FileStream("Qing.txt", FileMode.Append)
Dim Writer As New BinaryWriter(FS)
Dim Netstream As Socket = TcpServer.AcceptSocket
Dim ServerStream As New NetworkStream(Netstream)
Dim Reader As New BinaryReader(ServerStream)
Writer.Write(Reader.ReadBytes(ServerStream.Length))
Reader.Close()
ServerStream.Close()
Writer.Close()
FS.Close()
End Sub

客户端 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim T1 As New Thread(AddressOf RunClient)
T1.Start()
End Sub

Private Sub RunClient()
Dim Opened As New OpenFileDialog
Opened.Filter = "所有文件(*.*)|*.*"
Dim Result As DialogResult = Opened.ShowDialog
If Result = DialogResult.Cancel Then
Exit Sub
End If
Dim Fs As FileStream
Dim Reader As BinaryReader
Dim NetStream As NetworkStream
Dim TCPClient As New TcpClient
Dim Writer As BinaryWriter
Try
TCPClient.Connect("ncqingchuan", 6000)
NetStream = TCPClient.GetStream
Fs = New FileStream(Opened.FileName, FileMode.Open)
Reader = New BinaryReader(Fs)
Writer = New BinaryWriter(NetStream)
Writer.Write(Reader.ReadBytes(Fs.Length))
Catch ex As Net.Sockets.SocketException
MessageBox.Show(ex.Message, "测试", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Catch ev As System.ArgumentNullException
MessageBox.Show(ev.Message, "测试", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Catch ec As NullReferenceException
MessageBox.Show(ec.Message, "测试", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Finally
Reader.Close()
Writer.Close()
Fs.Close()
NetStream.Close()
End Try

End Sub
这只是个大体饿框架,具体的细节问题,比如文件大小啊,文件名啊这些还需要补充代码

2007-01-31 03:32
lkjkf
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2005-4-21
收藏
得分:0 

谢谢你啊!


 夫君子之行,静以修身,俭以养德,非淡泊无以明志,非宁静无以致远。
2007-03-19 16:46
快速回复:[求助]怎样在局域网中实现文件传输?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.094012 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved