Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Problem with .Net's NamedPipeServerStream and NamedPipeClientStream

Problem with .Net's NamedPipeServerStream and NamedPipeClientStream

Scheduled Pinned Locked Moved Visual Basic
csharpsysadminsecurityhelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BubbaGeeNH
    wrote on last edited by
    #1

    I'm trying to use .Net 3.5's NamedPipeServerStream and NamedPipeClientStream and I'm having some problems. I'm able to send one commmunication between the client and server programs but when the client attempts to connect a second time it hangs. Any idea what I'm doing wrong? SERVER CODE ----------- Imports System Imports System.IO Imports System.IO.Pipes Imports System.Threading Imports System.Windows.Forms Public Class SimServer Private Delegate Sub InvokeDelegate(ByVal text As String) Private newThread As New Thread(New ThreadStart(AddressOf PipeServer)) Private Sub PipeServer() ' Read the request from the client. Once the client has ' written to the pipe, its security token will be available. Dim pipeServer As New NamedPipeServerStream("CognexPipe", PipeDirection.InOut, 10) Dim sr As New StreamReader(pipeServer) Dim sw As New StreamWriter(pipeServer) Dim line As String Dim retline As String While (1) pipeServer.WaitForConnection() sw.AutoFlush = True While (pipeServer.IsConnected) If (sr.Peek > 0) Then line = sr.ReadLine() Me.BeginInvoke(New InvokeDelegate(AddressOf TextHandler), line) retline = "Received: " + line sw.WriteLine(retline) End If End While End While End Sub Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load newThread.Start() End Sub Private Sub Form3_Close(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.FormClosing newThread.Abort() End Sub Public Sub TextHandler(ByVal text As String) ReceivedBox.Text = text ReceivedBox.Update() End Sub End Class CLIENT CODE ----------- Imports System Imports System.IO Imports System.IO.Pipes Imports System.Threading Public Class SimClient Private Sub SendButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendButton.Click Dim pipeClient As New NamedPipeClientStream(".", "CognexPipe", PipeDirection.InOut) Dim sr As New StreamReader(pipeClient) Dim sw As New StreamWriter(pipeClient) Dim line As String Dim retline As String If Not pipeClient.IsConnected Then pipeClient.Connect() End If If pipeClient.IsConnected Then

    G P 2 Replies Last reply
    0
    • B BubbaGeeNH

      I'm trying to use .Net 3.5's NamedPipeServerStream and NamedPipeClientStream and I'm having some problems. I'm able to send one commmunication between the client and server programs but when the client attempts to connect a second time it hangs. Any idea what I'm doing wrong? SERVER CODE ----------- Imports System Imports System.IO Imports System.IO.Pipes Imports System.Threading Imports System.Windows.Forms Public Class SimServer Private Delegate Sub InvokeDelegate(ByVal text As String) Private newThread As New Thread(New ThreadStart(AddressOf PipeServer)) Private Sub PipeServer() ' Read the request from the client. Once the client has ' written to the pipe, its security token will be available. Dim pipeServer As New NamedPipeServerStream("CognexPipe", PipeDirection.InOut, 10) Dim sr As New StreamReader(pipeServer) Dim sw As New StreamWriter(pipeServer) Dim line As String Dim retline As String While (1) pipeServer.WaitForConnection() sw.AutoFlush = True While (pipeServer.IsConnected) If (sr.Peek > 0) Then line = sr.ReadLine() Me.BeginInvoke(New InvokeDelegate(AddressOf TextHandler), line) retline = "Received: " + line sw.WriteLine(retline) End If End While End While End Sub Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load newThread.Start() End Sub Private Sub Form3_Close(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.FormClosing newThread.Abort() End Sub Public Sub TextHandler(ByVal text As String) ReceivedBox.Text = text ReceivedBox.Update() End Sub End Class CLIENT CODE ----------- Imports System Imports System.IO Imports System.IO.Pipes Imports System.Threading Public Class SimClient Private Sub SendButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendButton.Click Dim pipeClient As New NamedPipeClientStream(".", "CognexPipe", PipeDirection.InOut) Dim sr As New StreamReader(pipeClient) Dim sw As New StreamWriter(pipeClient) Dim line As String Dim retline As String If Not pipeClient.IsConnected Then pipeClient.Connect() End If If pipeClient.IsConnected Then

      G Offline
      G Offline
      Gideon Engelberth
      wrote on last edited by
      #2

      Based on what I can see from the code without actually compiling it, I would guess that either the server code is blocking on the line If (sr.Peek > 0) or the thread is throwing an Exception when the pipe closes and ending that thread.

      1 Reply Last reply
      0
      • B BubbaGeeNH

        I'm trying to use .Net 3.5's NamedPipeServerStream and NamedPipeClientStream and I'm having some problems. I'm able to send one commmunication between the client and server programs but when the client attempts to connect a second time it hangs. Any idea what I'm doing wrong? SERVER CODE ----------- Imports System Imports System.IO Imports System.IO.Pipes Imports System.Threading Imports System.Windows.Forms Public Class SimServer Private Delegate Sub InvokeDelegate(ByVal text As String) Private newThread As New Thread(New ThreadStart(AddressOf PipeServer)) Private Sub PipeServer() ' Read the request from the client. Once the client has ' written to the pipe, its security token will be available. Dim pipeServer As New NamedPipeServerStream("CognexPipe", PipeDirection.InOut, 10) Dim sr As New StreamReader(pipeServer) Dim sw As New StreamWriter(pipeServer) Dim line As String Dim retline As String While (1) pipeServer.WaitForConnection() sw.AutoFlush = True While (pipeServer.IsConnected) If (sr.Peek > 0) Then line = sr.ReadLine() Me.BeginInvoke(New InvokeDelegate(AddressOf TextHandler), line) retline = "Received: " + line sw.WriteLine(retline) End If End While End While End Sub Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load newThread.Start() End Sub Private Sub Form3_Close(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.FormClosing newThread.Abort() End Sub Public Sub TextHandler(ByVal text As String) ReceivedBox.Text = text ReceivedBox.Update() End Sub End Class CLIENT CODE ----------- Imports System Imports System.IO Imports System.IO.Pipes Imports System.Threading Public Class SimClient Private Sub SendButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendButton.Click Dim pipeClient As New NamedPipeClientStream(".", "CognexPipe", PipeDirection.InOut) Dim sr As New StreamReader(pipeClient) Dim sw As New StreamWriter(pipeClient) Dim line As String Dim retline As String If Not pipeClient.IsConnected Then pipeClient.Connect() End If If pipeClient.IsConnected Then

        P Offline
        P Offline
        pointeman1
        wrote on last edited by
        #3

        Q. Did you ever figure this out? I'm trying to build a chat using NamedPipeServerStream & NamedPipeClientStream..

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups