static void SendLoop(NWConnection connection) { const int STDIN_FILENO = 0; DispatchIO.Read(STDIN_FILENO, 8192, DispatchQueue.MainQueue, (DispatchData readData, int stdinError) => { if (stdinError != 0) { warn($"Standard input error: {stdinError}"); } else if (readData == null || readData.Size == 0) { // Null data represent EOF // Send a "write close" on the connection, by sending // null data with the final message context marked as // complete. Note that it is valid to send with null // data but a non-null context. connection.Send((byte [] )null, context: NWContentContext.FinalMessage, isComplete: true, callback: (NWError error) => { if (error != null) { warn($"send error: {error.ErrorCode}"); } }); // Stop reading from stdin, do not schedule another SendLoop } else { connection.Send(readData, context: NWContentContext.DefaultMessage, isComplete: true, callback: (NWError error) => { if (error != null) { warn($"send error: {error.ErrorCode}"); } else { // continue reading from stdin SendLoop(connection); } }); } }); }