


下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、利用socket 套接字来进行文件传输速度还行,有需要完整版的可以联系我,免费公布。具体代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Net;using System.Net.Sockets;using System.IO;using System.Threading;namespace 发送文件
2、 public partial class Form1 : Form public Form1() CheckForIllegalCrossThreadCalls = false; InitializeComponent(); private Socket socket; private Thread a, b; private string filename; private TcpListener listen; private void start() listen = new TcpListener(14); listen.Start(); while (true) Socket s
3、= listen.AcceptSocket(); socket = s; b = new Thread(new ThreadStart(this.Receive); b.Start(); b.IsBackground = true; private void Receive() try Socket s = socket; NetworkStream ns = new NetworkStream(s); byte bytes = new byte1024 * 1024; int x = ns.Read(bytes, 0, bytes.Length); string mes = Encoding
4、.Unicode.GetString(bytes, 0, x).Split('|'); int length = int.Parse(mes0); SaveFileDialog sf = new SaveFileDialog(); sf.FileName = mes1; if (sf.ShowDialog() = DialogResult.OK) FileStream fs = new FileStream(sf.FileName, FileMode.Create, FileAccess.Write); BinaryWriter bw = new BinaryWriter(fs
5、); int total = 0; x = 0; while (total < length) x = ns.Read(bytes, 0, bytes.Length); bw.Write(bytes,0,x); total += x; bw.Close(); ns.Close(); fs.Close(); s.Close(); MessageBox.Show("ok"); catch (Exception ee) MessageBox.Show(ee.ToString(); private void button1_Click(object sender, Event
6、Args e) TcpClient client = new TcpClient(textBox1.Text.Trim(), 14); NetworkStream ns = client.GetStream(); OpenFileDialog aa = new OpenFileDialog(); if(aa.ShowDialog() = DialogResult.OK) string ss = aa.FileName.Split(''); filename = ssss.Length - 1; FileStream fs = new FileStream(aa.FileName
7、,FileMode.Open,FileAccess.Read); BinaryReader br = new BinaryReader(fs); Int64 size = fs.Length; MessageBox.Show(size.ToString(); byte bytes = new byte1024*1024; bytes = Encoding.Unicode.GetBytes(size.ToString()+'|'+filename+'|'); ns.Write(bytes,0,bytes.Length); Int64 total = 0; while (total < size) int x = br.Read(bytes,0,bytes.Length); ns.Write(bytes,0,x); total += x; private void F
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 环境监测仪表类型及应用考核试卷
- 封装材料特性考核试卷
- 派遣服务市场竞争力提升路径考核试卷
- 儿童性教育科学引导体系
- 婚内协议书范本
- 植物蓝染活动方案
- 楼梯装饰全年活动方案
- 油田职工比赛活动方案
- 油茶培训活动方案
- 河南废气处理活动方案
- 吊装施工安全协议书范本
- 2015海湾消防JB-QB-GST200 火灾报警控制器(联动型)安装使用说明书
- 中国各省区地图、基本资料
- 2025年广州市荔湾区招考社区居委会专职工作人员招考高频重点提升(共500题)附带答案详解
- 2025年全国普通话水平测试题标准试卷(共三十五套)
- 2025年全国保密知识竞赛经典试题库及答案(共270题)
- 2024年工厂车间主管年终总结
- 2025年中医治未病服务工作计划及措施
- 资金入股公司合同范例
- 出国境保密培训
- 使用错误评估报告(可用性工程)模版
评论
0/150
提交评论