


下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年厂级员工安全培训考试试题(完整版)
- 2025年员工安全培训考试试题附答案【达标题】
- 25年企业员工岗前安全培训考试试题附完整答案(全优)
- 知到智慧树网课:动物生物化学(华南农业大学)章节测试满分答案
- 2025年小餐馆员工的劳动合同
- 2025跨国合同争议解决
- 2025劳动合同模板下载
- 2025年智能移动电话机购销合同模板
- 2025会议的服务合同范本
- 2025苏州市北方建筑公司与上海地铁公司地铁建设合同违约争议案
- 2025商业综合体委托经营管理合同书
- 2024-2025学年北师大版生物七年级下册期中模拟生物试卷(含答案)
- T-CACM 1212-2019 中医妇科临床诊疗指南 产后小便不通
- 林业理论考试试题及答案
- 超市店长价格管理制度
- 2025-2030中国脑芯片模型行业市场发展趋势与前景展望战略研究报告
- 2025年河南省洛阳市洛宁县中考一模道德与法治试题(含答案)
- 掘进爆破、爆破安全知识
- 绿色工厂员工培训
- 2025年吉林省长春市中考一模历史模拟试题(含答案)
- 贵州民族建筑知到智慧树章节测试课后答案2024年秋贵州民族大学
评论
0/150
提交评论