易截截图软件、单文件、免安装、纯绿色、仅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#与Flash交互

C#与Flash交互 (转自小磊在线)
C#与Flash交互
前段日子公司要求做一个C#与Flash交互的东西,用来C#与短信猫通讯将数据传到Flash上显示与操作的应用。
第一步C#添加组件
打开VS2005-工具-选择工具箱项-COM组件-选择Shockwave Flash Object-确定
添加好组件往场景上拖放,如果提示注册需求注册
c# 注册控件-在运行输 ......

用java完成C#同样的DES对称加密

在一个项目中,客户用C#实现了DES加密,由于需要和java方面的程序进行数据交互,所以必须配合进行加解密工作。客户提供了密钥和向量,我看了看代码,c#做这个事情还蛮简单。 用java实现关键是我不字段怎么设置向量,一般用Cipher对象都是默认随机向量。搞了一阵,发现是用IvParameterSpec这个类来设置。于是有了以下代 ......

C#和Java中的方法注悉

非常简单,在C#中只需要在类的方法的上方敲三下"/"就自动帮你添加相关的代码,你只要按着填写就可以了,而Java则是输入"/**",它也会自动形成相关代码,具体代码如下:
C#
/// <summary>
/// 在此填写总体描述
///</summary>
/// <param name="name">这里填写参数name的描述</param>
public string ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号