I wanted the server to pass this information, to clients that requested it.
The basic work flow of my program is as follows:
One Client makes a petition of the information to the Server,The Server asks the wiimote for this information, the wiimote gives back the desired information. The Server then sends this info to the Client. The Server, then takes another petition, a petition which can come from the same Client, or from another completely different one. This cycle is repeated till the end of time, or till America's Next Top Model is on, and we need to start doing important stuff.
My project is therefore divided into 2 parts, the server part and the client part.
The Server part, is divided into:
- Creating the Server, have it listening on a certain address and Port for petitions.
- Having the Server always accept incoming connections to it.
- Once the server has a connection, the Server must attend this Client. It will create a Thread, for each of the Clients that want a connection with him.
- The "Thread Function" will receive a petition of what it's client wants. One Thread will receive from it's client a petition to obtain the Wii's Acceleration, another Thread might receive the petition to give the Pitch angle that the Wii has etc. Each Thread will receive a petition of a desired info from it's Client.
The Thread, in order to get this info, will call a function that depending on the String of text it receives, will send information to the client about the wiimote. This function, that sends to the Client it's desired information, receives therefore a *char,with the kind of information it wants, and the accept Socket,so this function can once and for all, write back to client, and send him the desired info.
Now, because Thread Functions can only be created with this
DWORD WINAPI ThreadProc(LPVOID lpParameter) syntax, we need to do a whole lot of
hassel of packing arguments in a temporary wrapper object andt hen unpacking
them inside some wrapper function. To understand how I managed it, I recommend you guys read this article,
it gives a nice explanation of the problem, and solves it in a very neat manner.
The Client on the otherhand:
- Tries to connect to the desired Server, if the desired Server is not available, the program finishes.
- Once it is connected to the Server, it sends to it, a command, if the command doesn't exist, the server sends back to the Client an error message, if the command does exists, the Server interprets, what kind of info the Client is looking for, according to the command it sent.
As for the part of Server, Client connections, I based my program on this tutorial. And it also helped me to know
that the accept function, only returns after it has received a connection!!!!!
I will post later a link to where my code can be downloaded. It is not that complicated, but it took me a while, to
understand how things were working, and to plan my program.
No comments:
Post a Comment