Post by D-FanI have a server process that will send me an unsolicited request via
a flag, etc. The Flag might be a certain character like the letter "B".
The letter "B" use telling me that There is information from me on
the server.
You don't need to flush the socket in order to handle such messages. You
do, however, need to design your protocol so that every packet has a header
on it (if you have not already done so) so that the client can determine
whether a given packet is an unsolicited message versus a reply to a comment
it sent to the server. You also need to make sure the server is sending
packets in a thread-safe manner so packets cannot overlap. And you need to
design both client and server to handle everything asynchronously so that an
unsolicated message is allowed to be sent while the server is doing other
things, and can arrive while the client is waiting for other data.
Post by D-FanSo, I respond with a value and the server will respond with the
messages that I have.
You don't need to send any acknowledgement in that situation. Have the
request for messages be its own command that the client can send to the
server at any time. The server message is just a notification to let the
client know that messages are available, nothing else. The client can then
send the request when it is ready to do so, and does not need to acknowledge
the server's notification.
Post by D-FanThe issue that I am looking looking to avoid is one where the server
send me multiple requests like 3 "B"'s before I get a chance to
respond to the first one. Once I get the first "B" I want to flush
the remaining values from the receive buffer before sending my
acknowledge back.
You are going about this all wrong. You should not be trying to flush
anything at all. Let the multiple "B" messages arrive normally. Simply set
a flag for yourself when the first one arrives, ignore any subsequent ones
that arrive while the flag is still set, and then clear the flag once you
send your request.
Gambit