On Oct 16, 2007, at 07:35, Ana Onarres wrote: > I am using the TWSocketServer and have seen the examples. I have 2 > doubts: > - It is necesary to create the ClientThread and TThrdSrvClient. In > the first one, I put the code for receiving data for client, send the > server and then send data that are sended for server. I don't see > clear the function of TThrdSrvClient. Can you explain me?
TThrdSrvClient is only available in TWSocketThrdServer (the multi-threaded version), not TWSocketServer (the single-thread version). It seems you are using TWSocketThrdServer, so the rest of my comment will assume this. ClientThread represents the thread which contains the clients. TThrdSrvClient is the client itself containing the socket object performing the actual TCP communication. The client objects are not TThread objects. So you have a representation like this: TWSocketThrdServer (Socket server) |- ClientThread1 (TThread object) | |- Client1 (TThrdSrvClient) | |- Client2 | |- Client3 | |- ClientThread2 | |- Client1 ... By default, each ClientThread contains only one client at a time (one thread per client), but this is configurable via the ClientsPerThread (or something like that) property. So, whenever a new client connects, if the last ClientThread created already contains its maximum amount of clients (default: 1), then a new ClientThread is created to hold this client. In this way you could have each thread hold, say, 10 clients each. Recall that TWSocket is ultimately asynchroneous and event-driven, so it can handle multiple clients on a single thread. > - In the event ClientDataAvailable, the client receive data. In this > case, the data can to come the socketserver and the client. Do I use > the Sender for distinguishing? ClientDataAvailable is triggered in the context of the ClientThread; that is, it triggers when Client data is received. The SocketServer data, when received, triggers OnDataAvailable. So you have two different methods: TWSocketThrdServer.OnDataAvailable => Server's data TWSocketThrdServer.OnClientDataAvailable => Client's data The OnClientDataAvailable event contains a reference to the actual Client object that received the data. The Sender will represent the ClientThread which owns that client. I hope this is clear, dZ. -- DZ-Jay [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be