Console.WriteLine("NamedPipeServerStream thread created.");
// Wait for a client to connect
pipeServer.WaitForConnection();
Console.WriteLine("Client connected.");
try
{
// Read the request from the client. Once the client has
// written to the pipe its security token will be available.
using (StreamReader sr = new StreamReader(pipeServer))
using (StreamWriter sw = new StreamWriter(pipeServer))
{
sw.AutoFlush = true;
// Verify our identity to the connected client using a
// string that the client anticipates.
sw.WriteLine("I am the true server!");
// Obtain the filename from the connected client.
string filename = sr.ReadLine();
// Read in the contents of the file while impersonating
// the client.
ReadFileToStream fileReader = new
ReadFileToStream(pipeServer, filename);
// Display the name of the user we are impersonating.
Console.WriteLine("Reading file: {0} as user {1}.",
pipeServer.GetImpersonationUserName(), filename);
pipeServer.RunAsClient(fileReader.Start);
pipeServer.Disconnect();
}
}
// Catch the IOException that is raised if the pipe is broken
// or disconnected.
catch (IOException e)
{
Console.WriteLine("ERROR: {0}", e.Message);
}
}
} // ServerThread()
} // PipeServer
class ReadFileToStream
{
private string m_filename;
private Stream m_stream;
public ReadFileToStream(Stream stream, string filename)
{
m_filename = filename;
m_stream = stream;
} // ReadFileToStream(stream, filename)
public void Start()
{
using (StreamWriter sw = new StreamWriter(m_stream))
{
string contents = File.ReadAllText(m_filename);
sw.WriteLine(contents);
sw.Flush();
}
} // Start()
} // ReadFileToStream
下面的示例演示使用 NamedPipeClientStream 类的客户端进程 。客户端连接服务器进程并向服务器发送一个文件名 。服务器随后将文件内容发送回客户端 。文件内容随后显示在控制台上 。
C#
VB
using System;
using System.IO;
using System.IO.Pipes;
using System.Security.Principal;
class PipeClient
{
static int numThreads = 4;
static void Main()
{
using (NamedPipeClientStream pipeClient =
new NamedPipeClientStream("localhost", "testpipe",
PipeDirection.InOut, PipeOptions.None,
TokenImpersonationLevel.Impersonation))
using (StreamWriter sw = new StreamWriter(pipeClient))
using (StreamReader sr = new StreamReader(pipeClient))
{
sw.AutoFlush = true;
pipeClient.Connect();
// Verify that this is the "true server"
if (sr.ReadLine() == "I am the true server!")
{
// The client security token is sent with the first write.
sw.WriteLine(@"c:\textfile.txt");
// Print the file to the screen.
char[] buffer = new char[32];
int n;
while ((n = sr.Read(buffer, 0, buffer.Length)) != 0)
{
Console.Write(buffer, 0, n);
}
}
else
{
Console.WriteLine("Server could not be verified.");
}
}
} // Main()
}
100分?。。。。ava与.net,编程的请进1.Java 是 简 单 vb.net进程间通信的
Java 与 C++ 极 为 相 似vb.net进程间通信,但 却 简 单 得 多 。高 级 编 程 语 言 的 所 有 特 性 中vb.net进程间通信,
不 是 绝 对 需 要 的 都 已 删 去 vb.net进程间通信了 。例 如 , Java 没 有 算 符 过 载、 标 题 文 件、
预 处 理、 指 针 运 算、 结 构、 联 合、 多 维 数 组、 模 板 及 隐 式 类 型 变 换 。如
果 你 知 道 一 点 C、 C++ 或 Pascal, 你 很 快 就 会 驾 驭 Java 。这 里 是 一 个 简 单 的 Java Hello World 程 序:
推荐阅读
- 电脑两个窗口怎么对齐打印,电脑打印两张
- chatgpt崩溃了,instantcatch崩溃
- 怎么拷贝移动硬盘,如何拷贝移动硬盘
- 电脑打开快手直播会卡,快手电脑直播卡住不动
- mysql驱动包怎么选 mysql驱动器下载教程
- 怎么做游戏账号手机版,手机怎么注册游戏账号
- 毕业设计小程序题目警务,适合毕设做的小程序题目
- 机械硬盘不断重启怎么办,机械硬盘老是自己消失重启后就出现了过一会儿就消失了
- java多线程代码 java多线程代码例子