named pipe and winforms

  • Thread starter Thread starter ieee488
  • Start date Start date
I

ieee488

Guest
I am trying to convert the Console application examples

NamedPipeServerStream Class (System.IO.Pipes)

NamedPipeClientStream Class (System.IO.Pipes)

to WinForm application

but with the client sending and the server receiving

When I run the code, the 5 letters sent by the client is not displayed in the text box on the server form until I close down the client program.

What is causing this and how do I fix it?



this is the code for the server

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
pipeServer = New NamedPipeServerStream("testpipe", PipeDirection.InOut)
TextBox1.Text = "NamedPipeServerStream object created."
TextBox1.Refresh()

TextBox1.Text = TextBox1.Text & vbCrLf & "Waiting for client connection..."
TextBox1.Refresh()

pipeServer.WaitForConnection()

TextBox1.Text = TextBox1.Text & vbCrLf & "Client connected."
TextBox1.Refresh()


Dim sr As New StreamReader(pipeServer)
Dim myString As String
myString = sr.ReadLine
TextBox1.Text = TextBox1.Text & vbCrLf & myString
TextBox1.Refresh()

While Not myString Is Nothing
myString = sr.ReadLine
TextBox1.Text = TextBox1.Text & vbCrLf & myString
TextBox1.Refresh()
End While


TextBox1.Text = TextBox1.Text & vbCrLf & "end"
TextBox1.Refresh()

End Sub



this is the code for the client

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim pipeClient As New NamedPipeClientStream("localhost", _
"testpipe", PipeDirection.InOut, PipeOptions.None)

' Connect to the pipe or wait until the pipe is available.
TextBox1.Text = "Attempting to connect to the pipe..."
TextBox1.Refresh()

pipeClient.Connect()

TextBox1.Text = TextBox1.Text & vbCrLf & "Connected to the pipe."
TextBox1.Text = TextBox1.Text & vbCrLf & "There are currently " & pipeClient.NumberOfServerInstances & " pipe server instances open."
TextBox1.Refresh()


Dim sw As New StreamWriter(pipeClient)
sw.AutoFlush = True
Dim myBuffer() As Char = {"a", "b", "c", "d", "e"}
sw.Write(myBuffer)


TextBox1.Text = TextBox1.Text & vbCrLf & myBuffer
TextBox1.Text = TextBox1.Text & vbCrLf & "end"


End Sub

Continue reading...
 
Back
Top