You do not want to have your echo line in the sockread event. Or, at least, you don't want it until a check that shows you're done reading from the socket. Everything in the sockread event is done/checked for each line in the socketed file. So you are echoing after every line is read.
on *:sockread:socketname: {
sockread %data
set %output %output $chr(124) %data
}
on *:sockclose:socknetname: {
if (%output) {
echo -a %output
unset %output
}
else { echo -a No data. }
}
* This is a very basic example and probably needs "fleshed out" a bit depending on the data in the socketed file.
** If you have a LOT of text, you may have to use a binary variable instead.
EDIT: I put in an error check if you have no data from the socket. It can be edited or removed as needed.