I am looking for a really good layout of an Indy TCP client that works without error that uses a reader thread.
I have a button that is supposed to change text from connect to reconnect when the client changes connection status, but it does not work all the time.
Some Specific questions:
-If I have stuff in the Connection events, should I have the client.disconnect in a sycronized procedure or something? I have a button that is supposed to change from 'connect' to 'disconnect' and vice versa when the event is called, but It doesn't change even though I still get TMemo messages showing that it was called.
-How do I properly end a connection? From outside a reader thread and within a reader thread? I know something about Terminate, but if it is waiting for a header, it will not see that portion of the thread to terminate itself. I saw some examples of just .free ing the thread itself, but I don't know if that is safe.
-Can a thread properly start another thread?
-Can I safely write to a connection from within a thread while still writing to same connection from another thread? I have some packets that need to be handled autonomousely, and some are generated via commands in an input box. Is there a chance that, if both write at the same time, that the packets going out will be screwed up? I am using the FlushBuffer functions.
-I am connecting to a server that every packet has a header that has a length, a packet ID, and data. There are about 30 or so packet types/events that I need to take care of. Right now I am using a big WHILE CONNECTED CASE LOOP. Is there a better way of doing this?
Anyway, looking for stability without going overboard. Any help would be appreciated.
Please don't just give 2 lines of text, state the obvious, give commonly known links, and expect points for it. I hate that. :)