I am writing a windows service and a separate GUI program and i want them communicating with named pipes. The windows service is the pipe server and the GUI will be the client.
The problem is that when my client connects to the pipeServer my BeginRead async-callback keeps firing. The client hasn't send any data.
const int buffersize= 255;
byte[] buffer = new byte[buffersize];
private void newConnection(IAsyncResult iar) {
//stop waiting for connection
pipeServer.EndWaitForConnection(iar);
//register callback
beginreadResult = server.BeginRead(buffer, 0, buffFormaat, newMessage, pipeServer);
}
public void newMessage(IAsyncResult r)
{
try
{
pipeServer.EndRead(beginreadResult);
}catch(Exception e){
Console.WriteLine(e.Message);
System.Environment.Exit(0);
}
string message = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
Console.WriteLine("new message: " + message);
beginreadResult= server.BeginRead(buffer, 0, buffersize, newMessage, server);
}
I can't figure out why the newMessage() callback keeps being called, anybody ideas?