本文整理汇总了C#中System.IO.Pipes.NamedPipeServerStream类的典型用法代码示例。如果您正苦于以下问题:C# NamedPipeServerStream类的具体用法?C# NamedPipeServerStream怎么用?C# NamedPipeServerStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NamedPipeServerStream类属于System.IO.Pipes命名空间,在下文中一共展示了NamedPipeServerStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: startServer
private void startServer(object state)
{
try
{
var pipe = state.ToString();
using (var server = new NamedPipeServerStream(pipe, PipeDirection.Out))
{
server.WaitForConnection();
while (server.IsConnected)
{
if (_messages.Count == 0)
{
Thread.Sleep(100);
continue;
}
var bytes = _messages.Pop();
var buffer = new byte[bytes.Length + 1];
Array.Copy(bytes, buffer, bytes.Length);
buffer[buffer.Length - 1] = 0;
server.Write(buffer, 0, buffer.Length);
}
}
}
catch
{
}
}
示例2: NamedPipeWriteViaAsyncFileStream
public async Task NamedPipeWriteViaAsyncFileStream(bool asyncWrites)
{
string name = Guid.NewGuid().ToString("N");
using (var server = new NamedPipeServerStream(name, PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous))
{
Task serverTask = Task.Run(async () =>
{
await server.WaitForConnectionAsync();
for (int i = 0; i < 6; i++)
Assert.Equal(i, server.ReadByte());
});
WaitNamedPipeW(@"\\.\pipe\" + name, -1);
using (SafeFileHandle clientHandle = CreateFileW(@"\\.\pipe\" + name, GENERIC_WRITE, FileShare.None, IntPtr.Zero, FileMode.Open, (int)PipeOptions.Asynchronous, IntPtr.Zero))
using (var client = new FileStream(clientHandle, FileAccess.Write, bufferSize: 3, isAsync: true))
{
var data = new[] { new byte[] { 0, 1 }, new byte[] { 2, 3 }, new byte[] { 4, 5 } };
foreach (byte[] arr in data)
{
if (asyncWrites)
await client.WriteAsync(arr, 0, arr.Length);
else
client.Write(arr, 0, arr.Length);
}
}
await serverTask;
}
}
示例3: MultiplexedPipeConnection
public MultiplexedPipeConnection(NamedPipeServerStream pipeServer, Microsoft.Samples.ServiceBus.Connections.QueueBufferedStream multiplexedOutputStream)
: base(pipeServer.Write)
{
this.pipeServer = pipeServer;
this.outputPump = new MultiplexConnectionOutputPump(pipeServer.Read, multiplexedOutputStream.Write, Id);
this.outputPump.BeginRunPump(PumpComplete, null);
}
示例4: PipesReader2
private static void PipesReader2(string pipeName)
{
try
{
var pipeReader = new NamedPipeServerStream(pipeName, PipeDirection.In);
using (var reader = new StreamReader(pipeReader))
{
pipeReader.WaitForConnection();
WriteLine("reader connected");
bool completed = false;
while (!completed)
{
string line = reader.ReadLine();
WriteLine(line);
if (line == "bye") completed = true;
}
}
WriteLine("completed reading");
ReadLine();
}
catch (Exception ex)
{
WriteLine(ex.Message);
}
}
示例5: EnsurePipeInstance
private void EnsurePipeInstance()
{
if (_stream == null)
{
var direction = PipeDirection.InOut;
var maxconn = 254;
var mode = PipeTransmissionMode.Byte;
var options = _asyncMode ? PipeOptions.Asynchronous : PipeOptions.None;
var inbuf = 4096;
var outbuf = 4096;
// TODO: security
try
{
_stream = new NamedPipeServerStream(_pipeAddress, direction, maxconn, mode, options, inbuf, outbuf);
}
catch (NotImplementedException) // Mono still does not support async, fallback to sync
{
if (_asyncMode)
{
options &= (~PipeOptions.Asynchronous);
_stream = new NamedPipeServerStream(_pipeAddress, direction, maxconn, mode, options, inbuf,
outbuf);
_asyncMode = false;
}
else
{
throw;
}
}
}
}
示例6: ListenForArguments
/// <summary>
/// Listens for arguments on a named pipe.
/// </summary>
/// <param name="state">State object required by WaitCallback delegate.</param>
private void ListenForArguments(Object state)
{
try
{
using (NamedPipeServerStream server = new NamedPipeServerStream(identifier.ToString()))
using (StreamReader reader = new StreamReader(server))
{
server.WaitForConnection();
List<String> arguments = new List<String>();
while (server.IsConnected)
{
string line = reader.ReadLine();
if (line != null && line.Length > 0)
{
arguments.Add(line);
}
}
ThreadPool.QueueUserWorkItem(new WaitCallback(CallOnArgumentsReceived), arguments.ToArray());
}
}
catch (IOException)
{ } //Pipe was broken
finally
{
ListenForArguments(null);
}
}
示例7: LaunchServer
private void LaunchServer(string pipeName)
{
try
{
Console.WriteLine("Creating server: " + pipeName);
server = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 4);
Console.WriteLine("Waiting for connection");
server.WaitForConnection();
reader = new StreamReader(server);
Task.Factory.StartNew(() =>
{
Console.WriteLine("Begin server read loop");
while (true)
{
try
{
var line = reader.ReadLine();
messages.Enqueue(line);
}
catch (Exception ex)
{
Console.WriteLine("ServerLoop exception: {0}", ex.Message);
}
}
});
}
catch (Exception ex)
{
Console.WriteLine("LaunchServer exception: {0}", ex.Message);
}
}
示例8: StartImportServer
private static async void StartImportServer()
{
Log.Info("Started server");
var exceptionCount = 0;
while(exceptionCount < 10)
{
try
{
using(var pipe = new NamedPipeServerStream("hdtimport", PipeDirection.In, 1, PipeTransmissionMode.Message))
{
Log.Info("Waiting for connecetion...");
await Task.Run(() => pipe.WaitForConnection());
using(var sr = new StreamReader(pipe))
{
var line = sr.ReadLine();
var decks = JsonConvert.DeserializeObject<JsonDecksWrapper>(line);
decks.SaveDecks();
Log.Info(line);
}
}
}
catch(Exception ex)
{
Log.Error(ex);
exceptionCount++;
}
}
Log.Info("Closed server. ExceptionCount=" + exceptionCount);
}
示例9: StartGeneralServer
private static async void StartGeneralServer()
{
Log.Info("Started server");
var exceptionCount = 0;
while(exceptionCount < 10)
{
try
{
using(var pipe = new NamedPipeServerStream("hdtgeneral", PipeDirection.In, 1, PipeTransmissionMode.Message))
{
Log.Info("Waiting for connecetion...");
await Task.Run(() => pipe.WaitForConnection());
using(var sr = new StreamReader(pipe))
{
var line = sr.ReadLine();
switch(line)
{
case "sync":
HearthStatsManager.SyncAsync(false, true);
break;
}
Log.Info(line);
}
}
}
catch(Exception ex)
{
Log.Error(ex);
exceptionCount++;
}
}
Log.Info("Closed server. ExceptionCount=" + exceptionCount);
}
示例10: Listener
public Listener(StreamReader reader, NamedPipeServerStream server)
{
serverStream = server;
SR = reader;
thread = new Thread(new ThreadStart(Run));
thread.Start();
}
示例11: CreatePipeServer
private void CreatePipeServer()
{
pipeServer = new NamedPipeServerStream("www.pmuniverse.net-installer", PipeDirection.InOut, 1, (PipeTransmissionMode)0, PipeOptions.Asynchronous);
pipeServer.WaitForConnection();
//pipeServer.BeginWaitForConnection(new AsyncCallback(PipeConnected), pipeServer);
Pipes.StreamString streamString = new Pipes.StreamString(pipeServer);
while (pipeServer.IsConnected) {
string line = streamString.ReadString();
if (!string.IsNullOrEmpty(line)) {
if (line.StartsWith("[Status]")) {
installPage.UpdateStatus(line.Substring("[Status]".Length));
} else if (line.StartsWith("[Progress]")) {
installPage.UpdateProgress(line.Substring("[Progress]".Length).ToInt());
} else if (line.StartsWith("[Component]")) {
installPage.UpdateCurrentComponent(line.Substring("[Component]".Length));
} else if (line == "[Error]") {
throw new Exception(line.Substring("[Error]".Length));
} else if (line == "[InstallComplete]") {
installPage.InstallComplete();
break;
}
}
}
pipeServer.Close();
}
示例12: Main
static void Main()
{
using (var pipeServer =
new NamedPipeServerStream("testpipe", PipeDirection.Out))
{
try
{
Console.WriteLine("NamedPipeServerStream object created.");
// Wait for a client to connect
Console.Write("Waiting for client connection...");
pipeServer.WaitForConnection();
Console.WriteLine("Client connected.");
// Read user input and send that to the client process.
using (StreamWriter sw = new StreamWriter(pipeServer))
{
sw.AutoFlush = true;
while (true)
{
Console.Write("Enter text: ");
sw.WriteLine(Console.ReadLine());
}
}
}
catch (IOException e)
{
Console.WriteLine("ERROR: {0}", e.Message);
}
}
}
示例13: Run
public void Run()
{
while (true)
{
NamedPipeServerStream pipeStream = null;
try
{
pipeStream = new NamedPipeServerStream(ConnectionName, PipeDirection.InOut, -1, PipeTransmissionMode.Message);
pipeStream.WaitForConnection();
if (_stop)
return;
// Spawn a new thread for each request and continue waiting
var t = new Thread(ProcessClientThread);
t.Start(pipeStream);
}
catch (Exception)
{
if (pipeStream != null)
pipeStream.Dispose();
throw;
}
}
// ReSharper disable once FunctionNeverReturns
}
示例14: PipeLink
public PipeLink(string spec)
{
this.pipe = new NamedPipeServerStream(spec, PipeDirection.InOut, 1, PipeTransmissionMode.Byte);
Thread t = new Thread(this.Connect);
t.Name = "Pipe Connector";
t.Start();
}
示例15: Run
/// <summary>
/// Runs the bundle with the provided command-line.
/// </summary>
/// <param name="commandLine">Optional command-line to pass to the bundle.</param>
/// <returns>Exit code from the bundle.</returns>
public int Run(string commandLine = null)
{
WaitHandle[] waits = new WaitHandle[] { new ManualResetEvent(false), new ManualResetEvent(false) };
int returnCode = 0;
int pid = Process.GetCurrentProcess().Id;
string pipeName = String.Concat("bpe_", pid);
string pipeSecret = Guid.NewGuid().ToString("N");
using (NamedPipeServerStream pipe = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1))
{
using (Process bundleProcess = new Process())
{
bundleProcess.StartInfo.FileName = this.Path;
bundleProcess.StartInfo.Arguments = String.Format("{0} -burn.embedded {1} {2} {3}", commandLine ?? String.Empty, pipeName, pipeSecret, pid);
bundleProcess.StartInfo.UseShellExecute = false;
bundleProcess.StartInfo.CreateNoWindow = true;
bundleProcess.Start();
Connect(pipe, pipeSecret, pid, bundleProcess.Id);
PumpMessages(pipe);
bundleProcess.WaitForExit();
returnCode = bundleProcess.ExitCode;
}
}
return returnCode;
}