tags:

views:

70

answers:

1

Am creating a lanmessenger in c#. And i have the code to receive and send messages through a port, but I am having a 'minor' confusion regarding how to use them. Should I constantly call the function that listens to the port from which incoming messages are to be received in each event?.. If so, then how do i call the function which shall send messages?

+1  A: 

Either use the asynchronous methods (e.g. BeginReceive), or look at threading...

If you use the asynchronous methods, you won't get bogged down by polling, because you will receive a callback when data is received.

If you use threading, you can poll (for example by checking the Available property of a TcpClient in a loop), and it won't prevent the rest of your code from executing, because the polling will be in its own thread.

Daniel LeCheminant
Thanks a lot... I was adamant at using synchronous connections but that obviously will make life harder.
Avik
@Avik: If you don't want to use the asynch stuff, Threading works (that's usually the approach that I take)
Daniel LeCheminant