title: C# Chat - TCP P2P
body: <p>I am working on a Peer-to-Peer chat program but have ran across an issue: Running the client and server simultaneously. I do not want a dedicated server to manage connections. I believe the solution may be asynchronous direct connections, but I am not sure. </p>
  
  <p>What I am trying to accomplish is to be able to run the program between two hosts, the program will be started and begin trying to connect to an ip address specified by a text box. At the same time, it will also start listening for incoming connections on the localhost ip address.   </p>
  
  <p>***I am using tcp, because on the off chance something is corrupted the message will not be able to be read (it is encrypted)</p>
  
  <p>Issues:
  1) It is conceivable a client could be waiting for a period of time before the other program tries to connect. So should some form of a loop must be utilized? If so, how?</p>
  
  <p>2) I assume I need to use multi-threading, with one thread for the server part and one thread for the client part, but an issue is keeping them from hanging. Since both programs are identical there way be a way to listen and simultaneously attempt to connect to the other host.</p>
  
  <p>3) I am also having trouble with making my server listen for connections to it, and do not know how to automatically have it pull the ip address from my computer.</p>
  
  <p>Thanks for any help.</p>
  
  <p>EDIT: This is on a LAN only.</p>