Hi everybody! I'm trying to write a toy program of a peer to peer chat. I'm not really developing using the .NET library since I need bluetooth support for a Windows Mobile application, but that's not the clue since all I need by now is a higher level code (pseudocode), since I'm still confused on what I have to do.
Since the program is peer to peer, I won't write client code and server code, but just a single code that will act for both (that's what the peer to peer paradigm is about). The program can only connect to a single client each time (to make it simple at first, that's only a 1on1 chat and not a multiperson chat).
That's how the program should behave (if my ideas are correct), let's call A and B the two endpoints of the communication:
1a) the application starts,
1b) a listening thread is launched which hangs on a (not sure if blocking or nonblocking) accept() call, waiting for a connection to come
2) the user A selects the remote endpoint (B's one) to connect (that should not be a problem)3) the user A connects to the selected remote endpoint: A's listening thread stops, so A is no more listening for an incoming connection, while B accept the incoming connection and after that B's listening thread also stops, and neither B is listening anymore for incoming connections.
4) either A or B can choose to send a message, which will be received by the counterpart (using read()/write() API's on a socket)
5) repeat step 4 until someone disconnects
6a) either A or B can disconnect (by choising to disconnect(), but mind this could also happen in an undesired way because of line problems)
6b) the connection is over
7) repeat step 1b-6b until the program is closed
My question is about the listening thread, which I don't know how to synchronously start/stop on both endpoints when a connection has begun or is over. Here's the state machine which I think should describe the behavior (mind that my drawing skill is even worse than my programming one :): http://img26.imageshack.us/img26/5539/disegno2r.jpg
Any ideas? Thank you for your patience,
there in the deepest well of dreams // echoed a distant song // I hearkened to the hallowed voice // stirred from ageless sleep // through this barren soil you came // sweet scent of spring // came and cast the earth in bloom // lent your light to meTuesday, December 22, 2009 1:25 PM
Hello! Thank you for your support. I'll study the code and probabily come up with further questions.
there in the deepest well of dreams // echoed a distant song // I hearkened to the hallowed voice // stirred from ageless sleep // through this barren soil you came // sweet scent of spring // came and cast the earth in bloom // lent your light to meTuesday, January 05, 2010 9:38 AM