最近刚开始学C#的流,不知道怎么用Socket传送文件,知道把文件做成文件流什么的,自己也写了一个小程序,但是运行的时候报错。想看一个具体的实现的例子~~~有这方面代码的希望能给我看看,谢谢!!!我的邮箱是[email protected]
解决方案 »
- c# 操作excel2007,滿足條件的數據寫入oracle
- 简单正则
- 定义变量,后面加个问号是什么意思??
- 如何实现点击一个button实现在一个textbox生成一串序列号
- C# invoke 能向主线程反馈消息吗?
- c#动态执行代码
- 请教各位大哥 ,为什么这个存储过程 当数据库数据大于99条, 它就只能取到99条,大于99的都取不到,为什么
- .net2.0没有数据窗体向导吗?
- 急急急急~~~~~~~。为什么这段代码无法删除数据库上的数据?
- 一个关于DataGrid的难题
- winform 的 radiobutton 怎么绑定 bool值
- ############简单时间转换问题 100分相送 不够再加 请大家帮忙!!!##########
http://www.it023.com/software/develop/donet/2004-04-12/1081758641d14122.html
http://www.mscenter.edu.cn/laputa/article/2004-8/0/13/8093.xml
// Uses the GetStream public method to return the NetworkStream.
try{
NetworkStream networkStream = tcpClient.GetStream();
if(networkStream.CanWrite){
Byte[] sendBytes = Encoding.ASCII.GetBytes("Is anybody there?");
networkStream.Write(sendBytes, 0, sendBytes.Length);
}
else{
Console.WriteLine("You cannot write data to this stream.");
tcpClient.Close();
return;
}
if(networkStream.CanRead){
// Reads NetworkStream into a byte buffer.
byte[] bytes = new byte[tcpClient.ReceiveBufferSize];
// Read can return anything from 0 to numBytesToRead.
// This method blocks until at least one byte is read.
networkStream.Read(bytes, 0, (int) tcpClient.ReceiveBufferSize);
// Returns the data received from the host to the console.
string returndata = Encoding.ASCII.GetString(bytes);
Console.WriteLine("This is what the host returned to you: " + returndata);
}
else{
Console.WriteLine("You cannot read data from this stream.");
tcpClient.Close();
return;
}
}
catch (Exception e ) {
Console.WriteLine(e.ToString());
}