资源简介
局域网里的文件传送,网了找了一天最后从别的人的源码里重写了一个才可以用,源码里修改下IP地址,默认是192.168.1.100,端口10001,主窗体点击接收窗体打开一个新窗体作接收端,点击发送选择文件即可

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Net.Sockets;
using System.Net;
namespace 文件发送
{
public partial class Form1 : Form
{
private string filePathSend = null;
private string fileNameSend;
private Thread fileThreadSend;
private TcpClient fileTcpClientSend;
private BinaryReader brSend = null;
private float sendFloat = 0 sendFile = 0;
private float sendfloat = 0 acceptfloat = 0;
private int timeFlagSend = 0;
private bool sendFlag = true;
public Form1()
{
InitializeComponent();
}
private void 发送_Click(object sender EventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();
openFile.ShowDialog();
filePathSend = openFile.FileName;
fileNameSend = Path.GetFileName(filePathSend);
fileThreadSend = new Thread(new ThreadStart(fileBeginSend));
fileThreadSend.Start();
}
//文件发送
private void fileBeginSend()
{
int FlagFile = 0;
string filenamesend = null;
if (File.Exists(filePathSend) == false)
{
MessageBox.Show(“没有选择文件“);
return;
}
//////////////////////////////////////
// ListView.CheckedListViewItemCollection checkedItemsFile = listView1.CheckedItems;
// if (item.SubItems[0].Text.ToString().Equals(Dns.GetHostName()+“-本机“))
// {
//MessageBox.Show(“不许给自己以送文件“);
//return;
// }
fileTcpClientSend = new TcpClient();
fileTcpClientSend.Connect(IPAddress.Parse(“192.168.1.100“) 10001);
if (fileTcpClientSend.Connected == true)
{
NetworkStream nsSend = fileTcpClientSend.GetStream();
byte[] writeSend = new byte[2048];
byte[] readSend = new byte[1];
brSend = null;
brSend = new BinaryReader(File.Open(filePathSend FileMode.Open));
writeSend = Encoding.GetEncoding(“gb2312“).GetBytes(“1“ + brSend.baseStream.Length.ToString() + “:“ + fileNameSend + “:“);
nsSend.Write(writeSend 0 writeSend.Length);
int nreadSend = nsSend.Read(readSend 0 readSend.Length);
if (fileNameSend.Length > 11)
filenamesend = fileNameSend.Substring(0 8) + “...“;
else
filenamesend = fileNameSend;
if (readSend[0].Equals(53))//对方取消发送
{
//Message
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 16896 2015-08-28 00:11 文件发送\文件发送\bin\Debug\文件发送.exe
文件 36352 2015-08-28 00:11 文件发送\文件发送\bin\Debug\文件发送.pdb
文件 14328 2015-08-28 00:12 文件发送\文件发送\bin\Debug\文件发送.vshost.exe
文件 490 2007-07-21 01:33 文件发送\文件发送\bin\Debug\文件发送.vshost.exe.manifest
文件 7864 2015-08-28 00:12 文件发送\文件发送\Form1.cs
文件 4845 2015-08-28 00:07 文件发送\文件发送\Form1.Designer.cs
文件 5814 2015-08-28 00:07 文件发送\文件发送\Form1.resx
文件 725 2015-08-28 00:12 文件发送\文件发送\obj\Debug\文件发送.csproj.FileListAbsolute.txt
文件 909 2015-08-28 00:07 文件发送\文件发送\obj\Debug\文件发送.csproj.GenerateResource.Cache
文件 16896 2015-08-28 00:11 文件发送\文件发送\obj\Debug\文件发送.exe
文件 180 2015-08-28 00:07 文件发送\文件发送\obj\Debug\文件发送.Form1.resources
文件 36352 2015-08-28 00:11 文件发送\文件发送\obj\Debug\文件发送.pdb
文件 180 2015-08-27 23:40 文件发送\文件发送\obj\Debug\文件发送.Properties.Resources.resources
文件 180 2015-08-28 00:06 文件发送\文件发送\obj\Debug\文件发送.接收窗.resources
文件 497 2015-08-27 23:52 文件发送\文件发送\Program.cs
文件 1366 2015-08-27 23:28 文件发送\文件发送\Properties\AssemblyInfo.cs
文件 2874 2015-08-27 23:28 文件发送\文件发送\Properties\Resources.Designer.cs
文件 5612 2015-08-27 23:28 文件发送\文件发送\Properties\Resources.resx
文件 1097 2015-08-27 23:28 文件发送\文件发送\Properties\Settings.Designer.cs
文件 249 2015-08-27 23:28 文件发送\文件发送\Properties\Settings.settings
文件 9476 2015-08-28 00:10 文件发送\文件发送\接收窗.cs
文件 4073 2015-08-28 00:06 文件发送\文件发送\接收窗.Designer.cs
文件 5814 2015-08-28 00:06 文件发送\文件发送\接收窗.resx
文件 3715 2015-08-27 23:40 文件发送\文件发送\文件发送.csproj
文件 926 2015-08-27 23:28 文件发送\文件发送.sln
..A..H. 13824 2015-08-28 00:12 文件发送\文件发送.suo
目录 0 2015-08-27 23:28 文件发送\文件发送\obj\Debug\TempPE
目录 0 2015-08-27 23:37 文件发送\文件发送\bin\Debug
目录 0 2015-08-28 00:11 文件发送\文件发送\obj\Debug
目录 0 2015-08-27 23:28 文件发送\文件发送\bin
............此处省略7个文件信息
- 上一篇:C# 写的CDT 规约解析 并打包发送程序
- 下一篇:C#模拟实现自动化测试架构
相关资源
- 逐步法线性回归C#源码
- 连连看游戏C#源码有提示和洗牌功能
- gerber 查看软件(C#源码)
- C#源码读取DXF文件
- 打印机监控(C#源码)
- 00后搞笑辞职信(C#源码)
- 桌面日历_V1.0(C#源码)
- 快递接口(C#源码以及文档)
- vb调用c#编写的串口DLL文件(vb源码
- BouncyCastle C#源码
- 拱猪扑克牌游戏C#源码
- 各类称重仪表C#源码
- C#坦克大战源代码全部用C#编写
- C#源码:批量自动去除图片白边
- [C#源码]内存搜索修改像金山游侠一下
- C#源码让windows系统待机休眠
- C#图书管理系统源码(含数据库)-附
- c#编写的绘图软件源码
- [C#源码]超市项目BS架构
- Modbus通讯协议-C#源码
- 发票套打[全C#源码]
- apk信息查看C#源码
- c#图书管理系统C#源码和SQL数据库
- 客户端根据服务器端的指令弹出提示
- 图书租借管理系统(C#源码 MySQL)
- [源码] C#编程 - 轻松入侵全班同学电脑
- 远程桌面控制C#源码
- 大学生就业咨询系统(C#源码)
- 餐饮管理系统(C#源码)
- 二手物品交易网站C#源码
评论
共有 条评论