本文整理汇总了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
开发者ID:VB.NET开发者,项目名称:System.IO.Pipes,代码行数:68,代码来源:PipeStream.Read
注:本文中的System.IO.Pipes.PipeStream.Read方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论