易截截图软件、单文件、免安装、纯绿色、仅160KB

c# 文件传输

send :
string path = "E:\\c#\\convey_file\\convey_file\\Form1.cs"; //要传输的文件
TcpClient client = new TcpClient();
client.Connect(IPAddress.Parse("192.168.0.52"),9999);
FileStream file = new FileStream(path,FileMode.Open,FileAccess.Read); //注意与receive的filestream的区别
BinaryReader binaryreader = new BinaryReader(file);
byte[] b = new byte[4098];
int data;
Console.WriteLine("正在发送文件");
while ((data = binaryreader.Read(b, 0, 4098)) != 0) //这个注意是将文件写成流的形式
{
client.Client.Send(b,data,SocketFlags.None); //发送文件流到目标机器
}
client.Client.Shutdown(SocketShutdown.Both);
binaryreader.Close();
file.Close();
receive:
private Socket s;
TcpListener tl;
public void lis()
{
string path = "d:\\1.cs"; //要传入文件的路径
tl = new TcpListener(9999);
tl.Start();
Console.WriteLine("等待接受");
s = tl.AcceptSocket();
FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write); //注意这个的属性和send端有所不同
BinaryWriter binarywrite = new BinaryWriter(fs);
int count;
byte[] b = new byte[4098];
while ((count = s.Receive(b, 4098, SocketFlags.None)) != 0) //这个是接受文件流
{
binarywrite.Write(b,0,count); //将接收的流用写成文件
}
binarywrite.Close();
fs.Close();
s.Close();
tl.Stop();
Console.WriteLine("文件传输完毕");


相关文档:

C# asp.net如何使用MD5加密,解密

using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;namespace md5
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(UserMd5("8"));
Console.WriteLine(GetMd5Str("8"));
}
/**//// <summary>
/// MD5 16位加密 ......

在c#中的取得sql server存储过程的output参数

private void Create_Pz(string Sourcename)
        {
            string OutMsg;
            SqlParameter[] sortPara = { new SqlParameter("@ps_IsType", Pz ......

C#和Java中的方法注悉

非常简单,在C#中只需要在类的方法的上方敲三下"/"就自动帮你添加相关的代码,你只要按着填写就可以了,而Java则是输入"/**",它也会自动形成相关代码,具体代码如下:
C#
/// <summary>
/// 在此填写总体描述
///</summary>
/// <param name="name">这里填写参数name的描述</param>
public string ......

测试语法高亮的 C# 代码的 html fragment 生成

测试语法高亮的 C# 代码的 html fragment 生成:
用csdn blog API 发布.
下面是:
public class HtmlWriter
{
   static Dictionary _colors;
   static int _colorNum;
   static StringBuilder _colorString;

© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号