本文整理汇总了C#中System.IO.Pipes.NamedPipeServerStream.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:C# NamedPipeServerStream.ReadByte方法的具体用法?C# NamedPipeServerStream.ReadByte怎么用?C# NamedPipeServerStream.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Pipes.NamedPipeServerStream
的用法示例。
在下文中一共展示了NamedPipeServerStream.ReadByte方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
public void Start()
{
Console.WriteLine("Магазин создан. Pipe: {0}.", PipeName);
while (true)
{
pipeServer = CreatePipeServer();
pipeServer.WaitForConnection();
try
{
int userId = pipeServer.ReadByte();
var command = (Request)pipeServer.ReadByte();
if (userId == 0)
{
id += 1;
pipeServer.WriteByte((byte)id);
userId = id;
}
else
{
pipeServer.WriteByte((byte)userId);
}
switch (command)
{
case Request.GoSection:
HandleGoSection(userId);
break;
case Request.LeftSection:
HandleLeftSection(userId);
break;
case Request.IsVendorVacant:
HandleIsVendorVacant(userId);
break;
case Request.NewVendor:
HandleNewVendor(userId);
break;
case Request.NewBuyer:
HandleNewBuyer(userId);
break;
default:
Console.WriteLine("Неизвестная команда");
break;
}
pipeServer.WaitForPipeDrain();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
示例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: Main
static void Main(string[] args)
{
Console.Title = "Log - Trinix";
if (!Directory.Exists("Logs"))
Directory.CreateDirectory("Logs");
Parser parser = null;
while (true)
{
NamedPipeServerStream pipeServer = new NamedPipeServerStream("trinix");
pipeServer.WaitForConnection();
if (parser != null)
parser.Dispose();
// MemoryStream ms = new MemoryStream();
//parser = new Parser();
// parser.Parse(ms);
StreamWriter log = new StreamWriter("Logs\\" + String.Format("{0:yyyy-MM-dd-HH-mm-ss}", DateTime.Now) + ".log");
try
{
while (pipeServer.IsConnected)
{
int v = pipeServer.ReadByte();
if (v == -1)
break;
// ms.WriteByte((byte)v);
Console.Write((char)v);
log.Write((char)v);
}
pipeServer.Close();
log.Close();
}
catch
{
}
Console.Write(Environment.NewLine);
Console.WriteLine("----------- Connection ended -----------");
Console.Write(Environment.NewLine);
}
}
示例4: Start
public void Start()
{
Console.WriteLine("Обед философов начался ! Всего {0} столовых приборов !", _forksCount);
bool hasStarted = false;
while (_connectedPhilosopherCount > 0 || !hasStarted)
{
_pipeServer = CreateServerPipe();
_pipeServer.WaitForConnection();
var request = (Request)_pipeServer.ReadByte();
switch(request)
{
case Request.GetPhilosopherPosition:
AssignPhilosopherPosition();
hasStarted = true;
break;
case Request.Eat:
Eat();
break;
case Request.Think:
Think();
break;
case Request.Rest:
Rest();
break;
case Request.TakeFork:
TakeFork();
break;
case Request.PutFork:
PutDownFork();
break;
default:
break;
}
_pipeServer.WaitForPipeDrain();
}
Console.WriteLine("Все ушли !");
Console.ReadLine();
}
示例5: ReadFileName
private static string ReadFileName(NamedPipeServerStream server)
{
char ch;
var fileName = "";
while ((ch = (char)server.ReadByte()) != 0)
fileName += ch;
return fileName;
}