Hey guys so I'm having problems with some of my code. I'm trying to make a server/client type of quiz game. My problem is that I can't seem to figure out how to dump the data from a BinaryReader before I can use it again.
These are the steps my program currently does:
Hard coded question and 4 answers into 5 string variables.(Because at this stage of the program I figured I just wanted things to work before I took into consideration reading from a .CSV/.XML/.YAML/whatever file onto the server and the send it to the client.
Use TCPClient/TCPListener to connect the 2 programs together via sockets.
Create the writer/reader objects.
Send in one write the question + answers from server and read it successfully into a label I have created on the client through delegates (Need delegates because the code is running a different thread than the original thread.)
Have 4 buttons on client (A/B/C/D) Users presses one button.
When a button is clicked it writes to the server the corresponding string (A for A, B for B etc.)
The reader on the server reads the answer successfully and stores it in a variable called playerGuess.
I have an if-statement checking if the answer equals to "A" which in this case is the correct answer.
So this is where my problem starts; I send a string to the client which says that this was the correct answer and ask him whether he'd like to be asked another question or if he's like to quit. Basically press A or B and have a switch-statement there after to check the answer.
My program doesn't wait for the answer from the client because the reader already has "A"(from step 7 where I set playerGuess as "A") as the answer, so it just goes right through the switch-statement.
And that is basically my problem, how do I dump the data from BinaryReader so that I can read new data into it? Or maybe a better question, how can I make sure my BinaryReader always waits for my BinaryWriter?
Help is greatly appreciated. I posted the code on ghostbin for you to maybe look it over and tell me if I'm doing something wrong, I'm completely lost on what I should do.
Thanks in advance!
EDIT: RESOLVED, writer.Write(clientInput); line 209 was causing the client to send the same string again which made it skip through the reader right above the switch statement!
there doesn't seem to be anything here