public WriteString ( string outString ) : int | ||
outString | string | |
Résultat | int |
public static void Main(string[] args) { if (args.Length > 0) { if (args[0] == "spawnclient") { var pipeClient = new NamedPipeClientStream(".", "testpipe", PipeDirection.InOut, PipeOptions.None, TokenImpersonationLevel.Impersonation); Console.WriteLine("Connecting to server...\n"); pipeClient.Connect(); StreamString ss = new StreamString(pipeClient); if (ss.ReadString() == "I am the one true server!") { ss.WriteString(Environment.CurrentDirectory + "\\testdata.txt"); Console.Write(ss.ReadString()); } else { Console.WriteLine("Server could not be verified."); } pipeClient.Close(); Thread.Sleep(4000); // Give the client process some time to display results before exiting. } } else { Console.WriteLine("\n*** Named pipe client stream with impersonation example ***\n"); StartClients(); } }
private static void ServerThread(object data) { var pipeServer = new NamedPipeServerStream("testpipe", PipeDirection.InOut, numThreads); int threadId = Thread.CurrentThread.ManagedThreadId; pipeServer.WaitForConnection(); Console.WriteLine("Client connected on thread[{0}].", threadId); try { StreamString ss = new StreamString(pipeServer); ss.WriteString("I am the one true server!"); string filename = ss.ReadString(); ReadFileToStream fileReader = new ReadFileToStream(ss, filename); Console.WriteLine("Reading file: {0} on thread[{1}] as user: {2}.", filename, threadId, pipeServer.GetImpersonationUserName()); pipeServer.RunAsClient(fileReader.Start); } catch (IOException e) { Console.WriteLine("ERROR: {0}", e.Message); } pipeServer.Close(); }
private static void ServerThread(object data) { var pipeServer = new NamedPipeServerStream("testpipe", PipeDirection.InOut, numThreads); int threadId = Thread.CurrentThread.ManagedThreadId; pipeServer.WaitForConnection(); Console.WriteLine("Client connected on thread[{0}].", threadId); try { StreamString ss = new StreamString(pipeServer); ss.WriteString("I am the one true server!"); string filename = ss.ReadString(); ReadFileToStream fileReader = new ReadFileToStream(ss, filename); Console.WriteLine("Reading file: {0} on thread[{1}] as user: {2}.", filename, threadId, pipeServer.GetImpersonationUserName()); pipeServer.RunAsClient(fileReader.Start); } catch (IOException e) { Console.WriteLine("ERROR: {0}", e.Message); } pipeServer.Close(); }
public void Start() { string contents = File.ReadAllText(fn); ss.WriteString(contents); }