NamedPipeClientStream.Write not returning












3














I'm trying to develop two applications which, while running, communicate to each other through named pipes, the server application create two pipes, one to send data to clients, the other to receive data from it.



Writing and reading operations are handled in another thread by using a Task, there are no problems while creating the pipes or connecting to them.



There is a problem when the client attempts to write data in the pipe, once the Write method is called, the execution just stops.



//Server code

//NamedPipesManager is a class created by me.

while (!TasksStopper.IsCancellationRequested)
{
if (!NamedPipesManager.IsConnected(OutPipe) & !NamedPipesManager.IsConnected(InPipe))
{
OutPipe.WaitForConnection();
InPipe.WaitForConnection();
}
CanReceiveMessages.WaitOne(); //The server start reading data only when signaled by the client, so that there is always data to read.
MessagesSemaphore.WaitOne(); //The methods of the class can be run only by one thread at a time, a Semaphore is used to regulate access.
NamedPipesManager.ReceiveMessage(InPipe, out MessageReceived.MessageType, out MessageReceived.Response);
if (MessageReceived.MessageType == NamedPipesManager.MESSAGES.CUSTOM_PROJECT_PATH_REQUEST)
{
MessagesSemaphore.WaitOne();
NamedPipesManager.SendMessage(OutPipe, NamedPipesManager.MESSAGES.CUSTOM_PROJECT_PATH_REQUEST, Convert.ToString(CustomProjectsPath));
}
else if (MessageReceived.MessageType == NamedPipesManager.MESSAGES.DEFAULT_PROJECTS_PATH_REQUEST)
{
MessagesSemaphore.WaitOne();
NamedPipesManager.SendMessage(OutPipe, NamedPipesManager.MESSAGES.DEFAULT_PROJECTS_PATH_REQUEST, DefaultProjectsPath);
}
}
if (NamedPipesManager.IsConnected(OutPipe))
{
MessagesSemaphore.WaitOne();
NamedPipesManager.SendMessage(OutPipe, NamedPipesManager.MESSAGES.DISCONNECT, null);
OutPipe.WaitForPipeDrain();
}

//Client code

NamedPipeClientStream HubInPipe = null;
NamedPipeClientStream HubOutPipe = null;
while (!TasksStopper.IsCancellationRequested)
{
HubInPipe = NamedPipesManager.ConnectToNamedPipe(null, "ProjectExchangeAppOutPipe", NamedPipesManager.PIPE_DIRECTION.IN);
HubInPipe.ReadMode = PipeTransmissionMode.Message;
HubOutPipe = NamedPipesManager.ConnectToNamedPipe(null, "ProjectExchangeAppInPipe", NamedPipesManager.PIPE_DIRECTION.OUT);
HubOutPipe.ReadMode = PipeTransmissionMode.Message;
PipesConnectedEvent.Set();
SendMessageEvent.WaitOne();
MessagesSemaphore.WaitOne();
NamedPipesManager.SendMessage(HubOutPipe, MessageType, MessageToSend);
HubWaitHandle.Set();
MessagesSemaphore.WaitOne();
NamedPipesManager.ReceiveMessage(HubInPipe, out ReceivedMessage.MessageType, out ReceivedMessage.Response);
if (ReceivedMessage.MessageType == NamedPipesManager.MESSAGES.CUSTOM_PROJECT_PATH_REQUEST || ReceivedMessage.MessageType == NamedPipesManager.MESSAGES.DEFAULT_PROJECTS_PATH_REQUEST)
{
ReceivedMessages.Add(ReceivedMessage);
MessageReceivedEvent.Set();
}
else if (ReceivedMessage.MessageType == NamedPipesManager.MESSAGES.SETTINGS_PROFILE_CHANGED)
{
DialogResult result = MessageBox.Show("...", "Avviso", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
{
ProfileName = ReceivedMessage.Response;
}
}
else if (ReceivedMessage.MessageType == NamedPipesManager.MESSAGES.DISCONNECT)
{
NamedPipesManager.ClosePipe(HubInPipe);
NamedPipesManager.ClosePipe(HubOutPipe);
}
}
if (NamedPipesManager.IsConnected(HubInPipe) & NamedPipesManager.IsConnected(HubOutPipe))
{
NamedPipesManager.ClosePipe(HubInPipe);
NamedPipesManager.ClosePipe(HubOutPipe);
}
else if (NamedPipesManager.IsConnected(HubInPipe) & !NamedPipesManager.IsConnected(HubOutPipe))
{
NamedPipesManager.ClosePipe(HubInPipe);
}
else if (!NamedPipesManager.IsConnected(HubInPipe) & NamedPipesManager.IsConnected(HubOutPipe))
{
NamedPipesManager.ClosePipe(HubOutPipe);
}

//SendMessage method of NamedPipesManager class.

if (Message != null)
{
byte Buffer = Encoding.Default.GetBytes(MessageType.ToString("D") + " " + Message);
Pipe.Write(Buffer, 0, Buffer.Length); //L'esecuzione si blocca qui.
}
else
{
byte Buffer = Encoding.Default.GetBytes(MessageType.ToString("D"));
Pipe.Write(Buffer, 0, Buffer.Length); //L'esecuzione si blocca qui.
}
Semaphore.Release();

//ReceiveMessage method of NamedPipesManager class

MessageType = MESSAGES.NONE;
Message = null;
System.Diagnostics.Debugger.Break();
StringBuilder sb = new StringBuilder();
byte Buffer = new byte[10];
string Chunk = string.Empty;
while (Pipe.IsConnected)
{
int BytesRead = Pipe.Read(Buffer, 0, Buffer.Length);
do
{
Chunk = Encoding.Default.GetString(Buffer);
sb.Append(Chunk);
Buffer = new byte[10];
}
while (!Pipe.IsMessageComplete);
string MessageReceived = sb.ToString();
MessageType = (MESSAGES)Convert.ToInt32(MessageReceived[0].ToString());
if (MessageReceived.Length > 1)
{
Message = MessageReceived.Substring(3);
}
}
Semaphore.Release();









share|improve this question


















  • 1




    Could it be the case that the reading side is not reading? The pipe buffers might be full.
    – usr
    Nov 14 '18 at 19:05










  • The server starts to read data only when signaled by the client through a global EventWaitHandle, the client notifies the server only after writing to the pipe but, since the write operation never completes, the notification isn't sent.
    – dt_overflow
    Nov 14 '18 at 19:41












  • It seems better to not use an event at all but to make the server continuously read from the pipe. What do you need to event for?
    – usr
    Nov 14 '18 at 20:09










  • Without the event the server becomes unresponsive and the call of the client to the Write method still doesn't return.
    – dt_overflow
    Nov 14 '18 at 23:52










  • Understand why that happens and fix the bug. The event complicates the solution and makes it not work. Pipe buffers are limited. Both sender and receiver need to take that into account. The receiver must be able to receive partial messages and piece them together. Often, this is done by sending a length prefix.
    – usr
    Nov 15 '18 at 8:41
















3














I'm trying to develop two applications which, while running, communicate to each other through named pipes, the server application create two pipes, one to send data to clients, the other to receive data from it.



Writing and reading operations are handled in another thread by using a Task, there are no problems while creating the pipes or connecting to them.



There is a problem when the client attempts to write data in the pipe, once the Write method is called, the execution just stops.



//Server code

//NamedPipesManager is a class created by me.

while (!TasksStopper.IsCancellationRequested)
{
if (!NamedPipesManager.IsConnected(OutPipe) & !NamedPipesManager.IsConnected(InPipe))
{
OutPipe.WaitForConnection();
InPipe.WaitForConnection();
}
CanReceiveMessages.WaitOne(); //The server start reading data only when signaled by the client, so that there is always data to read.
MessagesSemaphore.WaitOne(); //The methods of the class can be run only by one thread at a time, a Semaphore is used to regulate access.
NamedPipesManager.ReceiveMessage(InPipe, out MessageReceived.MessageType, out MessageReceived.Response);
if (MessageReceived.MessageType == NamedPipesManager.MESSAGES.CUSTOM_PROJECT_PATH_REQUEST)
{
MessagesSemaphore.WaitOne();
NamedPipesManager.SendMessage(OutPipe, NamedPipesManager.MESSAGES.CUSTOM_PROJECT_PATH_REQUEST, Convert.ToString(CustomProjectsPath));
}
else if (MessageReceived.MessageType == NamedPipesManager.MESSAGES.DEFAULT_PROJECTS_PATH_REQUEST)
{
MessagesSemaphore.WaitOne();
NamedPipesManager.SendMessage(OutPipe, NamedPipesManager.MESSAGES.DEFAULT_PROJECTS_PATH_REQUEST, DefaultProjectsPath);
}
}
if (NamedPipesManager.IsConnected(OutPipe))
{
MessagesSemaphore.WaitOne();
NamedPipesManager.SendMessage(OutPipe, NamedPipesManager.MESSAGES.DISCONNECT, null);
OutPipe.WaitForPipeDrain();
}

//Client code

NamedPipeClientStream HubInPipe = null;
NamedPipeClientStream HubOutPipe = null;
while (!TasksStopper.IsCancellationRequested)
{
HubInPipe = NamedPipesManager.ConnectToNamedPipe(null, "ProjectExchangeAppOutPipe", NamedPipesManager.PIPE_DIRECTION.IN);
HubInPipe.ReadMode = PipeTransmissionMode.Message;
HubOutPipe = NamedPipesManager.ConnectToNamedPipe(null, "ProjectExchangeAppInPipe", NamedPipesManager.PIPE_DIRECTION.OUT);
HubOutPipe.ReadMode = PipeTransmissionMode.Message;
PipesConnectedEvent.Set();
SendMessageEvent.WaitOne();
MessagesSemaphore.WaitOne();
NamedPipesManager.SendMessage(HubOutPipe, MessageType, MessageToSend);
HubWaitHandle.Set();
MessagesSemaphore.WaitOne();
NamedPipesManager.ReceiveMessage(HubInPipe, out ReceivedMessage.MessageType, out ReceivedMessage.Response);
if (ReceivedMessage.MessageType == NamedPipesManager.MESSAGES.CUSTOM_PROJECT_PATH_REQUEST || ReceivedMessage.MessageType == NamedPipesManager.MESSAGES.DEFAULT_PROJECTS_PATH_REQUEST)
{
ReceivedMessages.Add(ReceivedMessage);
MessageReceivedEvent.Set();
}
else if (ReceivedMessage.MessageType == NamedPipesManager.MESSAGES.SETTINGS_PROFILE_CHANGED)
{
DialogResult result = MessageBox.Show("...", "Avviso", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
{
ProfileName = ReceivedMessage.Response;
}
}
else if (ReceivedMessage.MessageType == NamedPipesManager.MESSAGES.DISCONNECT)
{
NamedPipesManager.ClosePipe(HubInPipe);
NamedPipesManager.ClosePipe(HubOutPipe);
}
}
if (NamedPipesManager.IsConnected(HubInPipe) & NamedPipesManager.IsConnected(HubOutPipe))
{
NamedPipesManager.ClosePipe(HubInPipe);
NamedPipesManager.ClosePipe(HubOutPipe);
}
else if (NamedPipesManager.IsConnected(HubInPipe) & !NamedPipesManager.IsConnected(HubOutPipe))
{
NamedPipesManager.ClosePipe(HubInPipe);
}
else if (!NamedPipesManager.IsConnected(HubInPipe) & NamedPipesManager.IsConnected(HubOutPipe))
{
NamedPipesManager.ClosePipe(HubOutPipe);
}

//SendMessage method of NamedPipesManager class.

if (Message != null)
{
byte Buffer = Encoding.Default.GetBytes(MessageType.ToString("D") + " " + Message);
Pipe.Write(Buffer, 0, Buffer.Length); //L'esecuzione si blocca qui.
}
else
{
byte Buffer = Encoding.Default.GetBytes(MessageType.ToString("D"));
Pipe.Write(Buffer, 0, Buffer.Length); //L'esecuzione si blocca qui.
}
Semaphore.Release();

//ReceiveMessage method of NamedPipesManager class

MessageType = MESSAGES.NONE;
Message = null;
System.Diagnostics.Debugger.Break();
StringBuilder sb = new StringBuilder();
byte Buffer = new byte[10];
string Chunk = string.Empty;
while (Pipe.IsConnected)
{
int BytesRead = Pipe.Read(Buffer, 0, Buffer.Length);
do
{
Chunk = Encoding.Default.GetString(Buffer);
sb.Append(Chunk);
Buffer = new byte[10];
}
while (!Pipe.IsMessageComplete);
string MessageReceived = sb.ToString();
MessageType = (MESSAGES)Convert.ToInt32(MessageReceived[0].ToString());
if (MessageReceived.Length > 1)
{
Message = MessageReceived.Substring(3);
}
}
Semaphore.Release();









share|improve this question


















  • 1




    Could it be the case that the reading side is not reading? The pipe buffers might be full.
    – usr
    Nov 14 '18 at 19:05










  • The server starts to read data only when signaled by the client through a global EventWaitHandle, the client notifies the server only after writing to the pipe but, since the write operation never completes, the notification isn't sent.
    – dt_overflow
    Nov 14 '18 at 19:41












  • It seems better to not use an event at all but to make the server continuously read from the pipe. What do you need to event for?
    – usr
    Nov 14 '18 at 20:09










  • Without the event the server becomes unresponsive and the call of the client to the Write method still doesn't return.
    – dt_overflow
    Nov 14 '18 at 23:52










  • Understand why that happens and fix the bug. The event complicates the solution and makes it not work. Pipe buffers are limited. Both sender and receiver need to take that into account. The receiver must be able to receive partial messages and piece them together. Often, this is done by sending a length prefix.
    – usr
    Nov 15 '18 at 8:41














3












3








3







I'm trying to develop two applications which, while running, communicate to each other through named pipes, the server application create two pipes, one to send data to clients, the other to receive data from it.



Writing and reading operations are handled in another thread by using a Task, there are no problems while creating the pipes or connecting to them.



There is a problem when the client attempts to write data in the pipe, once the Write method is called, the execution just stops.



//Server code

//NamedPipesManager is a class created by me.

while (!TasksStopper.IsCancellationRequested)
{
if (!NamedPipesManager.IsConnected(OutPipe) & !NamedPipesManager.IsConnected(InPipe))
{
OutPipe.WaitForConnection();
InPipe.WaitForConnection();
}
CanReceiveMessages.WaitOne(); //The server start reading data only when signaled by the client, so that there is always data to read.
MessagesSemaphore.WaitOne(); //The methods of the class can be run only by one thread at a time, a Semaphore is used to regulate access.
NamedPipesManager.ReceiveMessage(InPipe, out MessageReceived.MessageType, out MessageReceived.Response);
if (MessageReceived.MessageType == NamedPipesManager.MESSAGES.CUSTOM_PROJECT_PATH_REQUEST)
{
MessagesSemaphore.WaitOne();
NamedPipesManager.SendMessage(OutPipe, NamedPipesManager.MESSAGES.CUSTOM_PROJECT_PATH_REQUEST, Convert.ToString(CustomProjectsPath));
}
else if (MessageReceived.MessageType == NamedPipesManager.MESSAGES.DEFAULT_PROJECTS_PATH_REQUEST)
{
MessagesSemaphore.WaitOne();
NamedPipesManager.SendMessage(OutPipe, NamedPipesManager.MESSAGES.DEFAULT_PROJECTS_PATH_REQUEST, DefaultProjectsPath);
}
}
if (NamedPipesManager.IsConnected(OutPipe))
{
MessagesSemaphore.WaitOne();
NamedPipesManager.SendMessage(OutPipe, NamedPipesManager.MESSAGES.DISCONNECT, null);
OutPipe.WaitForPipeDrain();
}

//Client code

NamedPipeClientStream HubInPipe = null;
NamedPipeClientStream HubOutPipe = null;
while (!TasksStopper.IsCancellationRequested)
{
HubInPipe = NamedPipesManager.ConnectToNamedPipe(null, "ProjectExchangeAppOutPipe", NamedPipesManager.PIPE_DIRECTION.IN);
HubInPipe.ReadMode = PipeTransmissionMode.Message;
HubOutPipe = NamedPipesManager.ConnectToNamedPipe(null, "ProjectExchangeAppInPipe", NamedPipesManager.PIPE_DIRECTION.OUT);
HubOutPipe.ReadMode = PipeTransmissionMode.Message;
PipesConnectedEvent.Set();
SendMessageEvent.WaitOne();
MessagesSemaphore.WaitOne();
NamedPipesManager.SendMessage(HubOutPipe, MessageType, MessageToSend);
HubWaitHandle.Set();
MessagesSemaphore.WaitOne();
NamedPipesManager.ReceiveMessage(HubInPipe, out ReceivedMessage.MessageType, out ReceivedMessage.Response);
if (ReceivedMessage.MessageType == NamedPipesManager.MESSAGES.CUSTOM_PROJECT_PATH_REQUEST || ReceivedMessage.MessageType == NamedPipesManager.MESSAGES.DEFAULT_PROJECTS_PATH_REQUEST)
{
ReceivedMessages.Add(ReceivedMessage);
MessageReceivedEvent.Set();
}
else if (ReceivedMessage.MessageType == NamedPipesManager.MESSAGES.SETTINGS_PROFILE_CHANGED)
{
DialogResult result = MessageBox.Show("...", "Avviso", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
{
ProfileName = ReceivedMessage.Response;
}
}
else if (ReceivedMessage.MessageType == NamedPipesManager.MESSAGES.DISCONNECT)
{
NamedPipesManager.ClosePipe(HubInPipe);
NamedPipesManager.ClosePipe(HubOutPipe);
}
}
if (NamedPipesManager.IsConnected(HubInPipe) & NamedPipesManager.IsConnected(HubOutPipe))
{
NamedPipesManager.ClosePipe(HubInPipe);
NamedPipesManager.ClosePipe(HubOutPipe);
}
else if (NamedPipesManager.IsConnected(HubInPipe) & !NamedPipesManager.IsConnected(HubOutPipe))
{
NamedPipesManager.ClosePipe(HubInPipe);
}
else if (!NamedPipesManager.IsConnected(HubInPipe) & NamedPipesManager.IsConnected(HubOutPipe))
{
NamedPipesManager.ClosePipe(HubOutPipe);
}

//SendMessage method of NamedPipesManager class.

if (Message != null)
{
byte Buffer = Encoding.Default.GetBytes(MessageType.ToString("D") + " " + Message);
Pipe.Write(Buffer, 0, Buffer.Length); //L'esecuzione si blocca qui.
}
else
{
byte Buffer = Encoding.Default.GetBytes(MessageType.ToString("D"));
Pipe.Write(Buffer, 0, Buffer.Length); //L'esecuzione si blocca qui.
}
Semaphore.Release();

//ReceiveMessage method of NamedPipesManager class

MessageType = MESSAGES.NONE;
Message = null;
System.Diagnostics.Debugger.Break();
StringBuilder sb = new StringBuilder();
byte Buffer = new byte[10];
string Chunk = string.Empty;
while (Pipe.IsConnected)
{
int BytesRead = Pipe.Read(Buffer, 0, Buffer.Length);
do
{
Chunk = Encoding.Default.GetString(Buffer);
sb.Append(Chunk);
Buffer = new byte[10];
}
while (!Pipe.IsMessageComplete);
string MessageReceived = sb.ToString();
MessageType = (MESSAGES)Convert.ToInt32(MessageReceived[0].ToString());
if (MessageReceived.Length > 1)
{
Message = MessageReceived.Substring(3);
}
}
Semaphore.Release();









share|improve this question













I'm trying to develop two applications which, while running, communicate to each other through named pipes, the server application create two pipes, one to send data to clients, the other to receive data from it.



Writing and reading operations are handled in another thread by using a Task, there are no problems while creating the pipes or connecting to them.



There is a problem when the client attempts to write data in the pipe, once the Write method is called, the execution just stops.



//Server code

//NamedPipesManager is a class created by me.

while (!TasksStopper.IsCancellationRequested)
{
if (!NamedPipesManager.IsConnected(OutPipe) & !NamedPipesManager.IsConnected(InPipe))
{
OutPipe.WaitForConnection();
InPipe.WaitForConnection();
}
CanReceiveMessages.WaitOne(); //The server start reading data only when signaled by the client, so that there is always data to read.
MessagesSemaphore.WaitOne(); //The methods of the class can be run only by one thread at a time, a Semaphore is used to regulate access.
NamedPipesManager.ReceiveMessage(InPipe, out MessageReceived.MessageType, out MessageReceived.Response);
if (MessageReceived.MessageType == NamedPipesManager.MESSAGES.CUSTOM_PROJECT_PATH_REQUEST)
{
MessagesSemaphore.WaitOne();
NamedPipesManager.SendMessage(OutPipe, NamedPipesManager.MESSAGES.CUSTOM_PROJECT_PATH_REQUEST, Convert.ToString(CustomProjectsPath));
}
else if (MessageReceived.MessageType == NamedPipesManager.MESSAGES.DEFAULT_PROJECTS_PATH_REQUEST)
{
MessagesSemaphore.WaitOne();
NamedPipesManager.SendMessage(OutPipe, NamedPipesManager.MESSAGES.DEFAULT_PROJECTS_PATH_REQUEST, DefaultProjectsPath);
}
}
if (NamedPipesManager.IsConnected(OutPipe))
{
MessagesSemaphore.WaitOne();
NamedPipesManager.SendMessage(OutPipe, NamedPipesManager.MESSAGES.DISCONNECT, null);
OutPipe.WaitForPipeDrain();
}

//Client code

NamedPipeClientStream HubInPipe = null;
NamedPipeClientStream HubOutPipe = null;
while (!TasksStopper.IsCancellationRequested)
{
HubInPipe = NamedPipesManager.ConnectToNamedPipe(null, "ProjectExchangeAppOutPipe", NamedPipesManager.PIPE_DIRECTION.IN);
HubInPipe.ReadMode = PipeTransmissionMode.Message;
HubOutPipe = NamedPipesManager.ConnectToNamedPipe(null, "ProjectExchangeAppInPipe", NamedPipesManager.PIPE_DIRECTION.OUT);
HubOutPipe.ReadMode = PipeTransmissionMode.Message;
PipesConnectedEvent.Set();
SendMessageEvent.WaitOne();
MessagesSemaphore.WaitOne();
NamedPipesManager.SendMessage(HubOutPipe, MessageType, MessageToSend);
HubWaitHandle.Set();
MessagesSemaphore.WaitOne();
NamedPipesManager.ReceiveMessage(HubInPipe, out ReceivedMessage.MessageType, out ReceivedMessage.Response);
if (ReceivedMessage.MessageType == NamedPipesManager.MESSAGES.CUSTOM_PROJECT_PATH_REQUEST || ReceivedMessage.MessageType == NamedPipesManager.MESSAGES.DEFAULT_PROJECTS_PATH_REQUEST)
{
ReceivedMessages.Add(ReceivedMessage);
MessageReceivedEvent.Set();
}
else if (ReceivedMessage.MessageType == NamedPipesManager.MESSAGES.SETTINGS_PROFILE_CHANGED)
{
DialogResult result = MessageBox.Show("...", "Avviso", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
{
ProfileName = ReceivedMessage.Response;
}
}
else if (ReceivedMessage.MessageType == NamedPipesManager.MESSAGES.DISCONNECT)
{
NamedPipesManager.ClosePipe(HubInPipe);
NamedPipesManager.ClosePipe(HubOutPipe);
}
}
if (NamedPipesManager.IsConnected(HubInPipe) & NamedPipesManager.IsConnected(HubOutPipe))
{
NamedPipesManager.ClosePipe(HubInPipe);
NamedPipesManager.ClosePipe(HubOutPipe);
}
else if (NamedPipesManager.IsConnected(HubInPipe) & !NamedPipesManager.IsConnected(HubOutPipe))
{
NamedPipesManager.ClosePipe(HubInPipe);
}
else if (!NamedPipesManager.IsConnected(HubInPipe) & NamedPipesManager.IsConnected(HubOutPipe))
{
NamedPipesManager.ClosePipe(HubOutPipe);
}

//SendMessage method of NamedPipesManager class.

if (Message != null)
{
byte Buffer = Encoding.Default.GetBytes(MessageType.ToString("D") + " " + Message);
Pipe.Write(Buffer, 0, Buffer.Length); //L'esecuzione si blocca qui.
}
else
{
byte Buffer = Encoding.Default.GetBytes(MessageType.ToString("D"));
Pipe.Write(Buffer, 0, Buffer.Length); //L'esecuzione si blocca qui.
}
Semaphore.Release();

//ReceiveMessage method of NamedPipesManager class

MessageType = MESSAGES.NONE;
Message = null;
System.Diagnostics.Debugger.Break();
StringBuilder sb = new StringBuilder();
byte Buffer = new byte[10];
string Chunk = string.Empty;
while (Pipe.IsConnected)
{
int BytesRead = Pipe.Read(Buffer, 0, Buffer.Length);
do
{
Chunk = Encoding.Default.GetString(Buffer);
sb.Append(Chunk);
Buffer = new byte[10];
}
while (!Pipe.IsMessageComplete);
string MessageReceived = sb.ToString();
MessageType = (MESSAGES)Convert.ToInt32(MessageReceived[0].ToString());
if (MessageReceived.Length > 1)
{
Message = MessageReceived.Substring(3);
}
}
Semaphore.Release();






c# .net winforms named-pipes






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 18:53









dt_overflow

162




162








  • 1




    Could it be the case that the reading side is not reading? The pipe buffers might be full.
    – usr
    Nov 14 '18 at 19:05










  • The server starts to read data only when signaled by the client through a global EventWaitHandle, the client notifies the server only after writing to the pipe but, since the write operation never completes, the notification isn't sent.
    – dt_overflow
    Nov 14 '18 at 19:41












  • It seems better to not use an event at all but to make the server continuously read from the pipe. What do you need to event for?
    – usr
    Nov 14 '18 at 20:09










  • Without the event the server becomes unresponsive and the call of the client to the Write method still doesn't return.
    – dt_overflow
    Nov 14 '18 at 23:52










  • Understand why that happens and fix the bug. The event complicates the solution and makes it not work. Pipe buffers are limited. Both sender and receiver need to take that into account. The receiver must be able to receive partial messages and piece them together. Often, this is done by sending a length prefix.
    – usr
    Nov 15 '18 at 8:41














  • 1




    Could it be the case that the reading side is not reading? The pipe buffers might be full.
    – usr
    Nov 14 '18 at 19:05










  • The server starts to read data only when signaled by the client through a global EventWaitHandle, the client notifies the server only after writing to the pipe but, since the write operation never completes, the notification isn't sent.
    – dt_overflow
    Nov 14 '18 at 19:41












  • It seems better to not use an event at all but to make the server continuously read from the pipe. What do you need to event for?
    – usr
    Nov 14 '18 at 20:09










  • Without the event the server becomes unresponsive and the call of the client to the Write method still doesn't return.
    – dt_overflow
    Nov 14 '18 at 23:52










  • Understand why that happens and fix the bug. The event complicates the solution and makes it not work. Pipe buffers are limited. Both sender and receiver need to take that into account. The receiver must be able to receive partial messages and piece them together. Often, this is done by sending a length prefix.
    – usr
    Nov 15 '18 at 8:41








1




1




Could it be the case that the reading side is not reading? The pipe buffers might be full.
– usr
Nov 14 '18 at 19:05




Could it be the case that the reading side is not reading? The pipe buffers might be full.
– usr
Nov 14 '18 at 19:05












The server starts to read data only when signaled by the client through a global EventWaitHandle, the client notifies the server only after writing to the pipe but, since the write operation never completes, the notification isn't sent.
– dt_overflow
Nov 14 '18 at 19:41






The server starts to read data only when signaled by the client through a global EventWaitHandle, the client notifies the server only after writing to the pipe but, since the write operation never completes, the notification isn't sent.
– dt_overflow
Nov 14 '18 at 19:41














It seems better to not use an event at all but to make the server continuously read from the pipe. What do you need to event for?
– usr
Nov 14 '18 at 20:09




It seems better to not use an event at all but to make the server continuously read from the pipe. What do you need to event for?
– usr
Nov 14 '18 at 20:09












Without the event the server becomes unresponsive and the call of the client to the Write method still doesn't return.
– dt_overflow
Nov 14 '18 at 23:52




Without the event the server becomes unresponsive and the call of the client to the Write method still doesn't return.
– dt_overflow
Nov 14 '18 at 23:52












Understand why that happens and fix the bug. The event complicates the solution and makes it not work. Pipe buffers are limited. Both sender and receiver need to take that into account. The receiver must be able to receive partial messages and piece them together. Often, this is done by sending a length prefix.
– usr
Nov 15 '18 at 8:41




Understand why that happens and fix the bug. The event complicates the solution and makes it not work. Pipe buffers are limited. Both sender and receiver need to take that into account. The receiver must be able to receive partial messages and piece them together. Often, this is done by sending a length prefix.
– usr
Nov 15 '18 at 8:41












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306971%2fnamedpipeclientstream-write-not-returning%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306971%2fnamedpipeclientstream-write-not-returning%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?