下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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年智能电网用电设备项目规划申请报告
- 2026年商丘职业技术学院单招职业适应性考试题库附答案详解(研优卷)
- 2026年吕梁师范高等专科学校单招职业适应性测试题库附参考答案详解(能力提升)
- 2026年哈尔滨职业技术学院单招职业倾向性考试题库附答案详解(预热题)
- 新员工入职培训计划与指南范本
- 2025-2030高纯石墨原料市场供需分析及投资评估规划分析研究报告
- 2025-2030高端金融数据分析行业市场调研与发展前景与投行业务分析报告
- 2025-2030高端纺织服装品牌行业市场深度调研及可持续材料应用与风险资本进入路径探索报告
- 2025-2030高端电器产品市场供需分析及投资评估规划分析研究报告
- 2025-2030高端数控机床制造技术核心竞争产品分析产业进展与投资机会研究分析报告
- 威尔第课件教学课件
- 【北师大版】六年级下册数学教案-总复习《图形与位置》
- 售后部应急预案(3篇)
- 小学象棋校本课程
- 2025-2030中国液体化工内河运输市场发展潜力评估报告
- 2026年医保支付协议
- 东莞市财政投资代建项目资金监管实施细则
- GB/T 11918.2-2025工业用插头、固定式或移动式插座和器具输入插座第2部分:带插销和插套的电器附件的尺寸兼容性要求
- GB/T 37791-2025耐蚀合金焊带和焊丝
- 信息安全及保密意识培训课件
- 新能源材料与器件制备技术 课件全套 张云 第1-13章 概述-环境污染与治理
评论
0/150
提交评论