Serialized Object sending with NamedPipe not working

331 Views Asked by At

I am trying to send a serialized object (using XMLSerializer) thorugh a NamedPipe from a server process (.NET application exe) to a client process (.NET application exe), and vis versa.

The sequence is:

1) Server application opens Exe1 using Process.Start(processinfo) and then it starts the server pipe:

If server.IsConnected = False Then
      RaiseEvent ServerWaitingForRequests(pair)
      pair.Server.WaitForConnection()
End If

Inside Exe1 in Form_Load event, the client application connects to the server:

client = New NamedPipeClientStream(".", serverPipeName, PipeDirection.InOut)
If client.IsConnected = False Then client.Connect()
RaiseEvent ClientConnected(serverPipeName)

then I handle the ClientConnected event here:

Private Sub client_ClientConnected(serverName As String) Handles client.ClientConnected
   Timer1.Start(StartStatus.StartNew) 'Starts a timer (I already set the interval to 1 min)

When Timer1 fires the Elapsed event, I send a serialized object to the server exe, using this method:

'PipeMessage is a custom class I created, it is serialize and everything
Private Sub ReplyToServer(message As PipeMessage)
    m_mode = ExeRequestStatus.SendingReply
    RaiseEvent BeforeMessageSentToServer(message)
    Dim ser As New Xml.Serialization.XmlSerializer(message.GetType)
    ser.Serialize(client, message)
    client.WaitForPipeDrain()
    RaiseEvent AfterMessageSentToServer(message)
End Sub

Now the problem I have is that this line ser.Serialize(client, message) just completely hangs and the compiler doesn't move to the next line at all. This leaves the Server application waiting for client request forever.

On the server side, I call this method (from button1_click() after the client hit the .Serialize() line:

  Sub ListenToClient(exeInfo As ServerProcessPair)
    m_mode = ExeRequestStatus.WaitingForResponse
    RaiseEvent ServerWaitingForRequests(exeInfo)
    Dim ser As New Xml.Serialization.XmlSerializer(GetType(PipeMessage))
    Do
        Dim resobj As PipeMessage
        Try
            resobj = ser.Deserialize(exeInfo.Server)
            RaiseEvent ClientExeReplied(exeInfo, resobj)
            Exit Do
        Catch ex As Exception
        End Try
    Loop       
End Sub

What I am doing wrong? Is NamedPipe are bad choice for sending serialized objects between processes?

My system goal is to have 1 server app, which itself will spawn multiple client processes. And the goal is to have the server application sending and receive messages from all opened client processes.

0

There are 0 best solutions below