I have a limited knowledge of lnet but there doesn't seem to be anything very wrong in those snippets, other than the total lack of exception handling in both, and the multiple times you set n (without using it for anything) to the same value in one form or another in the first.
Can you share a compilable demo or more detailed code (p.e. to see where and how you're creating the streams, what OnCa() does etc.)? And what's there in the lines pointed to by the exception message?