本文整理汇总了VB.NET中System.IO.Pipes.PipeStream.Read方法的典型用法代码示例。如果您正苦于以下问题:VB.NET PipeStream.Read方法的具体用法?VB.NET PipeStream.Read怎么用?VB.NET PipeStream.Read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了PipeStream.Read方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: PipeStreamExample
' 导入命名空间
Imports System.IO
Imports System.IO.Pipes
Imports System.Diagnostics
Class PipeStreamExample
Private Shared matchSign() As Byte = {9, 0, 9, 0}
Public Shared Sub Main()
Dim args() As String = Environment.GetCommandLineArgs()
If args.Length < 2 Then
Dim clientProcess As New Process()
clientProcess.StartInfo.FileName = Environment.CommandLine
Using pipeServer As New AnonymousPipeServerStream( _
PipeDirection.In, HandleInheritability.Inheritable)
' Pass the client process a handle to the server.
clientProcess.StartInfo.Arguments = pipeServer.GetClientHandleAsString()
clientProcess.StartInfo.UseShellExecute = false
Console.WriteLine("[SERVER] Starting client process...")
clientProcess.Start()
pipeServer.DisposeLocalCopyOfClientHandle()
Try
If WaitForClientSign(pipeServer) Then
Console.WriteLine("[SERVER] Valid sign code received!")
Else
Console.WriteLine("[SERVER] Invalid sign code received!")
End If
Catch e As IOException
Console.WriteLine("[SERVER] Error: {0}", e.Message)
End Try
End Using
clientProcess.WaitForExit()
clientProcess.Close()
Console.WriteLine("[SERVER] Client quit. Server terminating.")
Else
Using pipeClient As PipeStream = New AnonymousPipeClientStream(PipeDirection.Out, args(1))
Try
Console.WriteLine("[CLIENT] Sending sign code...")
SendClientSign(pipeClient)
Catch e As IOException
Console.WriteLine("[CLIENT] Error: {0}", e.Message)
End Try
End Using
Console.WriteLine("[CLIENT] Terminating.")
End If
End Sub
Private Shared Function WaitForClientSign(inStream As PipeStream) As Boolean
Dim inSign() As Byte = Array.CreateInstance(GetType(Byte), matchSign.Length)
Dim len As Integer = inStream.Read(inSign, 0, matchSign.Length)
Dim valid = len.Equals(matchSign.Length)
While len > 0
len -= 1
valid = valid And (matchSign(len).Equals(inSign(len)))
End While
Return valid
End Function
Private Shared Sub SendClientSign(outStream As PipeStream)
outStream.Write(matchSign, 0, matchSign.Length)
End Sub
End Class