I'm trying to send 4 parameters - one integer, one bool and two strings from server to client using named pipes. I've tried different ways, but still not succeeded. First way - I just converted all parameters to string and tried to send like that, but on client I received all parameters as null:
Server code:
static void StartServer()
{
var server = new NamedPipeServerStream("PipesEnroll", PipeDirection.InOut);
while (true)
{
server.WaitForConnection();
StreamWriter writer = new StreamWriter(server);
string terminalTemplate;
string matcherTemplate;
int mathVersionNumber = 9;
int numberFingers;
bool isOk = Enroll.EnrollWithoutWCF(retrievedList, mathVersionNumber, out terminalTemplate, out matcherTemplate, out numberFingers);
writer.WriteLine(isOk.ToString());
writer.WriteLine(terminalTemplate);
writer.WriteLine(matcherTemplate);
writer.WriteLine(numberFingers.ToString());
writer.Flush();
server.Disconnect();
}
Client code:
using (var client = new NamedPipeClientStream(".", "PipesEnroll", PipeDirection.InOut))
{
client.Connect();
StreamReader reader = new StreamReader(client);
bool isOK = Convert.ToBoolean(reader.ReadLine());
string terminalTemplate = reader.ReadLine();
string matcherTemplate = reader.ReadLine();
int numberFingers = Convert.ToInt32(reader.ReadLine());
}
Second way I did is creating list of strings and serialized it on server, deserialized on client using BinaryFormatter, but got this exception:"System.Runtime.Serialization.SerializationException: End of Stream encountered before parsing was completed"
Server code:
var server = new NamedPipeServerStream("PipesEnroll", PipeDirection.InOut);
while (true)
{
server.WaitForConnection();
StreamWriter writer = new StreamWriter(server);
List<string> sendList = new List<string>();
sendList.Add(isOk.ToString());
sendList.Add(terminalTemplate);
sendList.Add(matcherTemplate);
sendList.Add(numberFingers.ToString());
BinaryFormatter formatterSerialize = new BinaryFormatter();
formatterSerialize.Serialize(writer.BaseStream, sendList);
writer.Flush();
server.Disconnect();
}
Client code:
using (var client = new NamedPipeClientStream(".", "PipesEnroll", PipeDirection.InOut))
{
client.Connect();
StreamReader reader = new StreamReader(client);
BinaryFormatter formatterDeserialize = new BinaryFormatter();
List<string> retrievedList = (List<string>) formatterDeserialize.Deserialize(reader.BaseStream);
}