1

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.

Ibrahim D.
  • 318
  • 4
  • 17
  • Do you get anything happening on the server side when you send the message at the client? – mageos Dec 04 '17 at 21:27
  • @mageos Yes, I updated the code, originally I did it like "when I first create the server and open the exe, I then run a method that listens to the client in infinte loop" but see the baove edit please, I made it a simple method call that calls .Deserialize() when I know for sure that the client did serialize – Ibrahim D. Dec 04 '17 at 21:32
  • If I were you I would comment out all code such as timers etc and only see if I can send one item from the server to the client and vice versa. Once that is working, I will then use timers, events etc. – CodingYoshi Dec 04 '17 at 21:43
  • @CodingYoshi I did just that, actually created another solution with 2 projects just to test the object sending between them, and it works perfectly, but once I apply the same thing to my original project with timers and everything, it just fails – Ibrahim D. Dec 04 '17 at 21:48
  • Are you using the same exe for both the client and the server? In your question you have mentioned only Exe1 so my assumption is you are using it for both. – CodingYoshi Dec 04 '17 at 22:00
  • @CodingYoshi Actually I have 1 Server application (exe file) and Client application (Exe1 or rather ClientExe1). Only 1 instance of Server application will be running and this server exe will open many client exe (ClientExe1 for example) – Ibrahim D. Dec 04 '17 at 22:08
  • @CodingYoshi The strange thing is that in the client application (which does the serialization) hangs on `.Serialize()` And the server application hangs also on `.Deserialize()`. So both Exes are hanging one on serialize and the other on desrialze – Ibrahim D. Dec 04 '17 at 22:11
  • Its hard for anyone to make sense of your code because there is code that we do not know what it means. For example, what is `client` in `ser.Serialize(client, message)`? – CodingYoshi Dec 04 '17 at 22:13
  • @CodingYoshi Sorry for the brief version, I thought the full version will be boring. But client refers to `client = New NamedPipeClientStream(".", serverPipeName, PipeDirection.InOut)` – Ibrahim D. Dec 04 '17 at 22:14

0 Answers0