private bool SendMessageAndWaitForAck(TcpClient socket, Message messageToSend) { var stream = socket.GetStream(); messageToSend.WriteTo(stream); stream.Flush(); var message = Message.Read(stream); return message.Header.Equals("ACK", StringComparison.OrdinalIgnoreCase); }
/// <summary> /// Create a channel to the master for receiving new transactions /// </summary> /// <param name="masterAddress"></param> public void OpenTransactionChannel(EndpointAddress masterAddress) { var tcpClient = new TcpClient(masterAddress.Uri.Host, masterAddress.Uri.Port); var msg = new Message("listen", String.Empty); var stream = tcpClient.GetStream(); msg.WriteTo(stream); stream.Flush(); _transactionMessageReader = new MessageReader(tcpClient, HandleTransactionMessage); _transactionMessageReader.Start(); }
/// <summary> /// Construct a sync message that lists all the stores we have and the last commited transaction id for each one /// then start a reader to process the updates the master will send to us /// </summary> /// <param name="masterAddress"></param> /// <param name="lastTxn"></param> public void SendSyncToMaster(EndpointAddress masterAddress, Dictionary<string, string> lastTxn) { var msg = new Message("sync", String.Empty); using(var writer = msg.GetContentWriter()) { foreach (var entry in lastTxn) { writer.WriteLine("{0}|{1}", entry.Key, entry.Value); } } var socket = new TcpClient(masterAddress.Uri.Host, masterAddress.Uri.Port); var socketStream = socket.GetStream(); msg.WriteTo(socketStream); socketStream.Flush(); var messageReader = new MessageReader(socket, HandleSyncMessage); messageReader.Start(); }
private void SendMessage(Stream networkStream, Message messageToSend) { messageToSend.WriteTo(networkStream); networkStream.Flush(); }