If you have the Mirth application already listening on port 10004 then you can't really have netcat also listening on that same port (the -l flag denotes listen). Perhaps you intended to write to the port rather than listen on it:
# Connect once and write many messages
( while :; do echo MSH....; sleep 3; done ) | nc -vvv localhost 10004
or
# Connect for each message
( while :; do echo MSH.... | nc -vvv localhost 10004; sleep 3; done )
Be aware that there are several different implementations of netcat. Every implementation seems to handle a different subset of flags...
Based on the new information in your question, here's another possible solution:
MESG=
while IFS= read -r LINE || test -n "$MESG"
do
if test -n "$LINE"
then
# Build the message block
test -z "$MESG" && MESG="$LINE" || MESG=$(printf "%s\n%s" "$MESG" "$LINE")
continue
fi
# Send the message block to the service
echo "$MESG" | nc -vvv localhost 10004
MESG=
sleep 3
done < /path/to/your/messagefile.txt