Re: [twsocket] TWSocketThrdServer
Thanks for your response. In the example ThrdSrvV2, it is necesary the Synchronization. Why? If every client has a separate work? In my application, the server sends data to all clients. How can i do this? Regards. Ana From: [EMAIL PROTECTED] To: twsocket@elists.org Date: Mon, 15 Oct 2007 09:38:21 -0400 Subject: Re: [twsocket] TWSocketThrdServer QUOTE: Anne What difference is between to use TWSocketThrdServer and use TWSocketServer with ClientThread? Which is better for me? END. TWSocketThrdServer spawns a new thread for each incoming client (or a new thread after the maximum amount of clients per threads has been reached). TWSocketServer handles all clients within the same thread in an asynchroneous, event-driven way. Both handle multiple clients at the same time, the difference is the thread model. If you use the multi-threaded version, keep in mind that development and debugging is substantially more complex because of thread-safety and synchronization issues. Also, keep in mind that spawning new threads is a resource-expensive process. Because of this, it is always recommended that you use the single-threaded approach unless you *absolutely need* to use multiple threads. As I have discovered recently on this list while discussing this topic, if you are not sure that you *absolutely need* to use multiple threads, then chances are you don't. TWSocketServer is able to handle many hundreds of concurrent clients in an efficient way, and its optimized for high-performance. However, if your clients have to do very intense or long processing with the data, this may prevent the other clients from processing data, so you may need to look into the multi-threaded approach. -dZ. -- 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 _ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ -- 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
Re: [twsocket] TWSocketThrdServer
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
Re: [twsocket] TWSocketThrdServer
I have other doubt. The application has data to server and the server has to send them to the clients. How can i do this? In the examples, i don't understand how the server send data to clients. Thanks. Regards. Anne. From: [EMAIL PROTECTED] To: twsocket@elists.org Date: Mon, 15 Oct 2007 15:54:50 +0200 Subject: Re: [twsocket] TWSocketThrdServer Ana Onarres wrote: Hello,I want to create a server socket that accepts connections of several clients. Every client, first, send data to server. This data are validated for server and then the server sends data to the client. What difference is between to use TWSocketThrdServer and use TWSocketServer with ClientThread? Which is better for me? With TWSocketServer you do not need client threads, TWSocketServer can easily serve hundreds of concurrent clients in a single thread. That includes fast sending and receiving data to/from multiple connected clients. It's because ICS uses non-blocking winsock API. You need threads only for lengthy, blocking tasks such as a DB query etc. For instance when a client requests data from a DB you start a thread that executes the query, when the thread has finished sent the result to the client. ICS works event-driven, means that most methods return immediately before they are finished, later when they finished another event is triggered where you take further action. -- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html Thanks for your attention.Regards. Anne. _ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ -- 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 _ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ -- 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
[twsocket] TWSocketThrdServer
Hello, I want to create a server socket that accepts connections of several clients. Every client, first, send data to server. This data are validated for server and then the server sends data to the client. What difference is between to use TWSocketThrdServer and use TWSocketServer with ClientThread? Which is better for me? Thanks for your attention. Regards. Anne. _ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ -- 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
Re: [twsocket] TWSocketThrdServer
Ana Onarres wrote: Hello, I want to create a server socket that accepts connections of several clients. Every client, first, send data to server. This data are validated for server and then the server sends data to the client. What difference is between to use TWSocketThrdServer and use TWSocketServer with ClientThread? Which is better for me? With TWSocketServer you do not need client threads, TWSocketServer can easily serve hundreds of concurrent clients in a single thread. That includes fast sending and receiving data to/from multiple connected clients. It's because ICS uses non-blocking winsock API. You need threads only for lengthy, blocking tasks such as a DB query etc. For instance when a client requests data from a DB you start a thread that executes the query, when the thread has finished sent the result to the client. ICS works event-driven, means that most methods return immediately before they are finished, later when they finished another event is triggered where you take further action. -- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html Thanks for your attention. Regards. Anne. _ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ -- 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
Re: [twsocket] TWSocketThrdServer
QUOTE: Anne What difference is between to use TWSocketThrdServer and use TWSocketServer with ClientThread? Which is better for me? END. TWSocketThrdServer spawns a new thread for each incoming client (or a new thread after the maximum amount of clients per threads has been reached). TWSocketServer handles all clients within the same thread in an asynchroneous, event-driven way. Both handle multiple clients at the same time, the difference is the thread model. If you use the multi-threaded version, keep in mind that development and debugging is substantially more complex because of thread-safety and synchronization issues. Also, keep in mind that spawning new threads is a resource-expensive process. Because of this, it is always recommended that you use the single-threaded approach unless you *absolutely need* to use multiple threads. As I have discovered recently on this list while discussing this topic, if you are not sure that you *absolutely need* to use multiple threads, then chances are you don't. TWSocketServer is able to handle many hundreds of concurrent clients in an efficient way, and its optimized for high-performance. However, if your clients have to do very intense or long processing with the data, this may prevent the other clients from processing data, so you may need to look into the multi-threaded approach. -dZ. -- 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
Re: [twsocket] TWSocketThrdServer friendly notice when disconnecting.
Hello dz, You have to loop through the connected clients to send them a message. and send the shutdown. Take care that clients may be disconnected while in the loop, so something like this: for n := 0 to Srv.ClientCount - 1 do try Srv.Clients[n].SendStr('bye'#13#10); Srv.Clients[n].ShutDown(1); except end; --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz Wednesday, October 10, 2007, 21:59, [EMAIL PROTECTED] wrote: Hello: I've noticed that when I use Shutdown(SD_BOTH), DisconnectAll(), or Free, all clients are disconnected gracefully. However, I was wondering if there is a way to intercept that the server is shutting down, so that I can send a Server is shutting down. Connection closed. message before closing. I guess I could loop through the collection of connected clients and send them a message, but I was wondering if there was a better way. -dZ. -- 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
Re: [twsocket] TWSocketThrdServer friendly notice when disconnecting.
Thanks, Wilfried. That's what I'm doing now. However, I'm doing it from the end of the Execute() method of the worker thread, right before destroying the server, like this: Procedure WorkerThread.Execute; Begin _InitializeSrv(); // create Try Srv.MessageLoop(); Finally Try For n := 0 to (Srv.ClientCount - 1) Do Begin Srv.Clients[n].SendStr('bye'#13#10); Srv.Clients[n].ShutDown(1); End; Finally Srv.Free; End; End; End; The problem that I saw was that Calling Shutdown(1) would cause the server to trigger OnClientDisconnect, which may fire *after* the thread and client were distroyed by Srv.Free, which will raise an exception that I would like to avoid if possible. So, what I did was not call ShutDown(1), and expect the shutdown to occur when destroying the Srv, like this: Try Srv.Shutdown(0); // make sure we do not accept anybody else! For n := 0 to (Srv.ClientCount - 1) Do Begin Srv.Clients[n].SendStr('bye'#13#10); End; Finally Srv.Free; // Shutdown clients as well End; Is that appropriate, or can you see something wrong with it? Thanks! dZ. P.S. I haven't received any messages from this list in the past two days. Is it still alive, or am I having e-mail issues? -- 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
Re: [twsocket] TWSocketThrdServer friendly notice whendisconnecting.
DZ-Jay wrote: Thanks, Wilfried. That's what I'm doing now. However, I'm doing it from the end of the Execute() method of the worker thread, right before destroying the server, like this: Procedure WorkerThread.Execute; Begin _InitializeSrv(); // create Try Srv.MessageLoop(); Finally Try For n := 0 to (Srv.ClientCount - 1) Do Begin Srv.Clients[n].SendStr('bye'#13#10); Srv.Clients[n].ShutDown(1); End; Finally Srv.Free; End; End; End; Iterating thru Srv.Clients is not the way to go!! It is not thread-save and will most likely throw strange AVs. Instead iterate thru the thread-list and post a custom message to each thread, the inside the thread iterate thru each thread's client list, see TWSocketThrdServer.DisconnectAll as example. Now one problem is that TWSocketThrdServer has no public property ThreadList and TWsClientThread.PumpMessages doesn't fire an event OnMessage. So the code has to be tweaked a little bit for common use. The only reason why I started writing this component was to derive a SSL multi-threaded server from it only to be able to test thread-safety of the SSL code. The problem that I saw was that Calling Shutdown(1) would cause the server to trigger OnClientDisconnect, which may fire *after* the thread and client were distroyed by Srv.Free, which will raise an exception that I would like to avoid if possible. So, what I did was not call ShutDown(1), and expect the shutdown to occur when destroying the Srv, like this: Try Srv.Shutdown(0); // make sure we do not accept anybody else! Here Srv.Close is the correct method to call. -- Arno Garrels [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
Re: [twsocket] TWSocketThrdServer friendly notice whendisconnecting.
--- QUOTE: SZ If you do not want the ability to use multi-cores for communication threads, then async is the way to go. But IMO, it is an ill design since chipmakers are talking about 64-core CPUs and 10Gbps networks. --- END. Thanks, SZ. At this point I'm not so much concerned about complexity (although, of course, that is a concern), but more about performance and efficiency. I know that the arguments are always against multiple threads because they are harder to debug and synchronize, which is a very valid argument, and one that's biting me in the ass right now, but is that at the cost of a perceivable performance hit? Or is the async component not only simpler to use, but just as fast (or at least not significantly slower)? -dZ. -- 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
Re: [twsocket] TWSocketThrdServer friendly notice whendisconnecting.
On 10/11/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: --- QUOTE: Arno Garrels This is untested code. Also FThreadList has to be made public. Note that OnMessage would fire in different thread contexts but a single handler for all is fine. Hope this helps. --- END. I'll look into it. --- QUOTE: Arno Garrels I think it isn't very fast, I tested once with some stress clients and many concurrent connections successfully over many hours until that point it looked stable. In any case I won't use multi-threading if not absolutely necessary, simply because it's easier to code and to debug. TWSocketServer can handle many hundreds of concurrent connections in a single thread. --- END. Then I'm wondering if I should use TWSocketServer instead. Pardon my ignorance, as I haven't used the server components before and generally ignore any messages about them on this list, but would you (or Francois) say that its performance is good while handling potentially hundreds of concurrent connections? In actually, I don't expect my service application to serve more than 100 to 200 concurrent connections (and that's in an extreme case, perhaps once a month for a few hours). Thanks for all your help. -dZ. Hi, If you do not want the ability to use multi-cores for communication threads, then async is the way to go. But IMO, it is an ill design since chipmakers are talking about 64-core CPUs and 10Gbps networks. Best Regards, SZ -- 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
Re: [twsocket] TWSocketThrdServer friendly notice whendisconnecting.
Fastream Technologies wrote: I test my ICS-based MT proxy with 20k connections on our dual-core system. It performs 2GBps, local-to-local. So that's one CPU performance basically since the tester also uses CPU! I would not imagine such performance with single thread. Those numbers don't tell me much. I'm missing a serious comparison between an optimized MT and an optimzed ST server. One comparison was how many clients can be connected until the first is being rejected due to a full ListenBackLogQueue. Another was how long would it take until all clients finished their concurrent download. -- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html Best Regards, SZ On 10/11/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: --- QUOTE: SZ If you do not want the ability to use multi-cores for communication threads, then async is the way to go. But IMO, it is an ill design since chipmakers are talking about 64-core CPUs and 10Gbps networks. --- END. Thanks, SZ. At this point I'm not so much concerned about complexity (although, of course, that is a concern), but more about performance and efficiency. I know that the arguments are always against multiple threads because they are harder to debug and synchronize, which is a very valid argument, and one that's biting me in the ass right now, but is that at the cost of a perceivable performance hit? Or is the async component not only simpler to use, but just as fast (or at least not significantly slower)? -dZ. -- 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
[twsocket] TWSocketThrdServer stuck in destructor loop when killing threads
Hello: I'm having a problem with the TWSocketThrdServer. My application has a worker thread that contains a TWSocketThrdServer member to handle all incoming requests. When the main thread finishes, it sends a WM_QUIT message to the worker thread, which then finishes and frees the TWSocketThrdServer. However, if there are clients connected, the thrdserver stalls in its destructor, while waiting for all its threads to finish. It only loops forever when there are clients connected and the worker thread is terminated. But if there are no clients connected, it works fine. Can someone offer any help? Most likely I'm doing something wrong. (Below is an example of my code.) Also, I need to be able to terminate the entire application if something goes wrong while processing clients. What is the best way to do this? Should I post a message to the main thread from a TWSocketThrdServer event in the worker thread? Thanks! dZ. My code is somewhat like this (this is very much simplified): Interface Type TServerThrd = Class(TThread) Private FSocketSrv: TWSocketThrdServer; Public Constructor Create; Reintroduce; Destructor Destroy; Override; Procedure Execute; Override; End; TQApp = Class(TObject) Private FServerThrd : TServerThrd; Public Constructor Create; Destructor Destroy; Override; End; Implementation { TQApp } Constructor TQApp.Create; Begin FServerThrd := TServerThrd.Create(False); End; Destructor TQApp.Destroy Begin Try Try PostThreadMessage(FServerThrd.ThreadID,WM_QUIT,0,0); Finally FServerThrd.WaitFor; FServerThrd.Free; End; Finally Inherited Destroy; End; End; { TServerThrd } Constructor TServerThrd.Create; Begin Inherited Create(True); End; Destructor TServerThrd.Destroy; Begin Try If Assigned(FSocketSrv) Then Begin FSocketSrv.Free; // -- HERE! (waits forever) End; Finally Inherited Destroy; End; End; Procedure TServerThrd.Execute; Begin Try FSocketSrv := TWSocketThrdServer.Create(Nil); FSocketSrv.Listen(); FSocketSrv.MessageLoop; Finally // do other cleanup End; End; -- 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
Re: [twsocket] TWSocketThrdServer stuck in destructor loop when killing threads
Hello dz, Change this. Its from top of my head so can be syntax errors. You have to move the destroy of the server also in the Execute mehod: Destructor TServerThrd.Destroy; Begin Try // this must in the Execute method // If Assigned(FSocketSrv) Then Begin // FSocketSrv.Free; // -- HERE! (waits forever) // End; Finally Inherited Destroy; End; End; Procedure TServerThrd.Execute; Begin Try FSocketSrv := TWSocketThrdServer.Create(Nil); FSocketSrv.Listen(); FSocketSrv.MessageLoop; Finally // Add FSocketSrv.Free; End; End; --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz Thursday, October 4, 2007, 18:57, [EMAIL PROTECTED] wrote: Hello: I'm having a problem with the TWSocketThrdServer. My application has a worker thread that contains a TWSocketThrdServer member to handle all incoming requests. When the main thread finishes, it sends a WM_QUIT message to the worker thread, which then finishes and frees the TWSocketThrdServer. However, if there are clients connected, the thrdserver stalls in its destructor, while waiting for all its threads to finish. It only loops forever when there are clients connected and the worker thread is terminated. But if there are no clients connected, it works fine. Can someone offer any help? Most likely I'm doing something wrong. (Below is an example of my code.) Also, I need to be able to terminate the entire application if something goes wrong while processing clients. What is the best way to do this? Should I post a message to the main thread from a TWSocketThrdServer event in the worker thread? Thanks! dZ. My code is somewhat like this (this is very much simplified): Interface Type TServerThrd = Class(TThread) Private FSocketSrv: TWSocketThrdServer; Public Constructor Create; Reintroduce; Destructor Destroy; Override; Procedure Execute; Override; End; TQApp = Class(TObject) Private FServerThrd : TServerThrd; Public Constructor Create; Destructor Destroy; Override; End; Implementation { TQApp } Constructor TQApp.Create; Begin FServerThrd := TServerThrd.Create(False); End; Destructor TQApp.Destroy Begin Try Try PostThreadMessage(FServerThrd.ThreadID,WM_QUIT,0,0); Finally FServerThrd.WaitFor; FServerThrd.Free; End; Finally Inherited Destroy; End; End; { TServerThrd } Constructor TServerThrd.Create; Begin Inherited Create(True); End; Destructor TServerThrd.Destroy; Begin Try If Assigned(FSocketSrv) Then Begin FSocketSrv.Free; // -- HERE! (waits forever) End; Finally Inherited Destroy; End; End; Procedure TServerThrd.Execute; Begin Try FSocketSrv := TWSocketThrdServer.Create(Nil); FSocketSrv.Listen(); FSocketSrv.MessageLoop; Finally // do other cleanup End; End; -- 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
Re: [twsocket] TWSocketThrdServer stuck in destructor loopwhenkilling threads
[EMAIL PROTECTED] wrote: Now, since all exceptions are being swallowed by the TWSocket component, if I need to kill the entire app from, say, an event within the TWSocketThrdSrv (for example in OnBgException), should I post a message to the main thread, or is there a better way? You may want to detect when the ServerThread terminates in general the you can either restart the thread or terminate the application depending on a flag or error code sent in a custom message. In OnBgException the flag or error can be set, something like that. Procedure TServerThrd.Execute; Begin Try FSocketSrv := TWSocketThrdServer.Create(Nil); FSocketSrv.Listen(); FSocketSrv.MessageLoop; Finally // Add FSocketSrv.Free; PostMessage(AppHwnd, WM_SERVERTHREAD_WILL_TERMINATE_SOON, ErrorCode, RestartMe); End; End; -- Arno Garrels [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
Re: [twsocket] TWSocketThrdServer - Bogus OnDataAvailable triggeredwhen Closed.
You should call Shutdown to gracefully close the connection. If you want to call close, do it using an intermediate custom message. -- [EMAIL PROTECTED] Author of ICS (Internet Component Suite, freeware) Author of MidWare (Multi-tier framework, freeware) http://www.overbyte.be - Original Message - From: [EMAIL PROTECTED] To: twsocket@elists.org Sent: Wednesday, October 03, 2007 12:04 AM Subject: [twsocket] TWSocketThrdServer - Bogus OnDataAvailable triggeredwhen Closed. Hello: I'm using TWSocketThrdServer and processing client data from within the OnDataAvailable event handler (client is set to LineMode=True). I've noticed that if the data transaction is completed and I call Client.Close from within this event, the event is called again with the previous ReceivedStr. Here's a sample of the code I am using: Procedure TMyServer.HandleDataAvailable(Sender: TObject; Error: Word); Var DataStr: String; bDone: Boolean; Begin If (Error = 0) Then Begin With (Sender As TMyClient) Do Begin DataStr := ReceiveStr; // parse the DataStr and do // whatever needs to be done. // bDone may be set here. If (bDone) Then Begin SendLine('Sayonara.'); TMyClient(Sender).Close; // -- HERE! End; End; End Else Begin // Handle errors... TMyClient(Sender).Abort; End; End; When that Close method is called, the event is immediately re-entered with the same data. Am I doing something stupid? Thanks, -dZ. -- 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 -- 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
Re: [twsocket] TWSocketThrdServer - Bogus OnDataAvailable triggeredwhen Closed.
Isn't it what CloseDelayed is meant for? Francois Piette wrote: You should call Shutdown to gracefully close the connection. If you want to call close, do it using an intermediate custom message. -- [EMAIL PROTECTED] Author of ICS (Internet Component Suite, freeware) Author of MidWare (Multi-tier framework, freeware) http://www.overbyte.be - Original Message - From: [EMAIL PROTECTED] To: twsocket@elists.org Sent: Wednesday, October 03, 2007 12:04 AM Subject: [twsocket] TWSocketThrdServer - Bogus OnDataAvailable triggeredwhen Closed. Hello: I'm using TWSocketThrdServer and processing client data from within the OnDataAvailable event handler (client is set to LineMode=True). I've noticed that if the data transaction is completed and I call Client.Close from within this event, the event is called again with the previous ReceivedStr. Here's a sample of the code I am using: Procedure TMyServer.HandleDataAvailable(Sender: TObject; Error: Word); Var DataStr: String; bDone: Boolean; Begin If (Error = 0) Then Begin With (Sender As TMyClient) Do Begin DataStr := ReceiveStr; // parse the DataStr and do // whatever needs to be done. // bDone may be set here. If (bDone) Then Begin SendLine('Sayonara.'); TMyClient(Sender).Close; // -- HERE! End; End; End Else Begin // Handle errors... TMyClient(Sender).Abort; End; End; When that Close method is called, the event is immediately re-entered with the same data. Am I doing something stupid? Thanks, -dZ. -- 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 -- 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
Re: [twsocket] TWSocketThrdServer - Bogus OnDataAvailable triggeredwhen Closed.
Olivier Sannier wrote: Isn't it what CloseDelayed is meant for? CloseDelayed won't reenter the event, however to ensure that last data packets are received properly before the socket is closed call ShutDown() for a gracefull close in DataSent event handler. -- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html Francois Piette wrote: You should call Shutdown to gracefully close the connection. If you want to call close, do it using an intermediate custom message. -- [EMAIL PROTECTED] Author of ICS (Internet Component Suite, freeware) Author of MidWare (Multi-tier framework, freeware) http://www.overbyte.be - Original Message - From: [EMAIL PROTECTED] To: twsocket@elists.org Sent: Wednesday, October 03, 2007 12:04 AM Subject: [twsocket] TWSocketThrdServer - Bogus OnDataAvailable triggeredwhen Closed. Hello: I'm using TWSocketThrdServer and processing client data from within the OnDataAvailable event handler (client is set to LineMode=True). I've noticed that if the data transaction is completed and I call Client.Close from within this event, the event is called again with the previous ReceivedStr. Here's a sample of the code I am using: Procedure TMyServer.HandleDataAvailable(Sender: TObject; Error: Word); Var DataStr: String; bDone: Boolean; Begin If (Error = 0) Then Begin With (Sender As TMyClient) Do Begin DataStr := ReceiveStr; // parse the DataStr and do // whatever needs to be done. // bDone may be set here. If (bDone) Then Begin SendLine('Sayonara.'); TMyClient(Sender).Close; // -- HERE! End; End; End Else Begin // Handle errors... TMyClient(Sender).Abort; End; End; When that Close method is called, the event is immediately re-entered with the same data. Am I doing something stupid? Thanks, -dZ. -- 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 -- 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
Re: [twsocket] TWSocketThrdServer - BogusOnDataAvailabletriggeredwhen Closed.
Hello dz, Client.SendLine('-ERR Closing connection.'); Client.Shutdown(1); // Or CloseDelayed() ...? Yes. This way you are sure that the string will be received by the other end. --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz -- 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
[twsocket] TWSocketThrdServer - Bogus OnDataAvailable triggered when Closed.
Hello: I'm using TWSocketThrdServer and processing client data from within the OnDataAvailable event handler (client is set to LineMode=True). I've noticed that if the data transaction is completed and I call Client.Close from within this event, the event is called again with the previous ReceivedStr. Here's a sample of the code I am using: Procedure TMyServer.HandleDataAvailable(Sender: TObject; Error: Word); Var DataStr: String; bDone: Boolean; Begin If (Error = 0) Then Begin With (Sender As TMyClient) Do Begin DataStr := ReceiveStr; // parse the DataStr and do // whatever needs to be done. // bDone may be set here. If (bDone) Then Begin SendLine('Sayonara.'); TMyClient(Sender).Close; // -- HERE! End; End; End Else Begin // Handle errors... TMyClient(Sender).Abort; End; End; When that Close method is called, the event is immediately re-entered with the same data. Am I doing something stupid? Thanks, -dZ. -- 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
[twsocket] TWSocketThrdServer graceful shutdown
Hello: I using TWSocketThrdServer in a server application and was wondering if there is a recommended method to call for a graceful shutdown -- one that will stop listening when all current connections are completed. Thanks, -dZ. -- 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
Re: [twsocket] TWSocketThrdServer graceful shutdown
Hello dz, Just call Close method. server will stop listening. Note that calling Close will not stop current connections, it only stops listening. --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz Friday, September 28, 2007, 17:44, [EMAIL PROTECTED] wrote: Hello: I using TWSocketThrdServer in a server application and was wondering if there is a recommended method to call for a graceful shutdown -- one that will stop listening when all current connections are completed. Thanks, -dZ. -- 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
Re: [twsocket] TWSocketThrdServer graceful shutdown
[EMAIL PROTECTED] wrote: Hello: I using TWSocketThrdServer in a server application and was wondering if there is a recommended method to call for a graceful shutdown -- one that will stop listening when all current connections are completed. Call Close, that just stops listening, doesn't disconnect connected clients, if that's what you mean. -- Arno Garrels [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
Re: [twsocket] TWSocketThrdServer graceful shutdown
Thanks Wilfried. Close() will do it. What then does Shutdown(x) do? I see that Close() calls it with an argument of 1 (SD_SEND), which according to a comment is for graceful close. Does it stop sending data? -dZ. --- Original Message --- From: Wilfried Mestdagh[mailto:[EMAIL PROTECTED] Sent: 9/28/2007 12:03:57 PM To : twsocket@elists.org Cc : Subject : RE: Re: [twsocket] TWSocketThrdServer graceful shutdown Hello dz, Just call Close method. server will stop listening. Note that calling Close will not stop current connections, it only stops listening. --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz Friday, September 28, 2007, 17:44, [EMAIL PROTECTED] wrote: Hello: I using TWSocketThrdServer in a server application and was wondering if there is a recommended method to call for a graceful shutdown -- one that will stop listening when all current connections are completed. Thanks, -dZ. -- 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 -- 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
Re: [twsocket] TWSocketThrdServer graceful shutdown
Hello Arno, Most likely Wilfried is faster again ;-) most of the time you are faster :) --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz -- 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
Re: [twsocket] TWSocketThrdServer graceful shutdown
[EMAIL PROTECTED] wrote: Thanks Wilfried. Close() will do it. What then does Shutdown(x) do? I see that Close() calls it with an argument of 1 (SD_SEND), which according to a comment is for graceful close. Does it stop sending data? Most likely Wilfried is faster again ;-) Shutdown() initiates a bidirectional shutdown procedure of a connection, the listening socket however has no connection, so calling TWSocketServer.Close is fine. Call Shutdown(1) on the client socket when all data has been sent (OnDataSent), it disables subsequent sends on the socket, however data still pending in winsock buffer will be sent nevertheless. -- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html --- Original Message --- From: Wilfried Mestdagh[mailto:[EMAIL PROTECTED] Sent: 9/28/2007 12:03:57 PM To : twsocket@elists.org Cc : Subject : RE: Re: [twsocket] TWSocketThrdServer graceful shutdown Hello dz, Just call Close method. server will stop listening. Note that calling Close will not stop current connections, it only stops listening. --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz Friday, September 28, 2007, 17:44, [EMAIL PROTECTED] wrote: Hello: I using TWSocketThrdServer in a server application and was wondering if there is a recommended method to call for a graceful shutdown -- one that will stop listening when all current connections are completed. Thanks, -dZ. -- 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 -- 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
Re: [twsocket] TWSocketThrdServer graceful shutdown
Wilfried Mestdagh wrote: Hello Arno, Most likely Wilfried is faster again ;-) most of the time you are faster :) Isn't this list great? Where else do you get faster support for free software? g -- Arno Garrels [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
Re: [twsocket] TWSocketThrdServer graceful shutdown
Friday, September 28, 2007, 20:36, Arno Garrels wrote: Wilfried Mestdagh wrote: Hello Arno, Most likely Wilfried is faster again ;-) most of the time you are faster :) Isn't this list great? Where else do you get faster support for free software? g Indeed. Sometime I have the feeling we are all friends in this community helping each other ! This really give a good feeling :) -- 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
Re: [twsocket] TWSocketThrdServer graceful shutdown
--- Original Message --- From: Arno Garrels[mailto:[EMAIL PROTECTED] Isn't this list great? Where else do you get faster support for free software? g Yes, it is. Thank you both for your quick responses. -dZ. -- 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