[twsocket] Refusing client connection
Hi, I built a server program, and a few clients. Each client has a specific scope and uses some of the server features. On of the client software has the ability to restart the server. That's where the problem begins. While the server is shutting down, I must broadcast a shutdown to all connected client softwares so they can close gracefully. But, during this process, I don't want any new connection to be made. How would be the best way to deal with this? TIA, Clément -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] Notifying clients that TWSocketThrdServer is shutting down
Hi, I'm working on a project (Delphi 7, and ICS V5). I built a server using TWSocketThrdServer and the clients are derived from TWSocketThrdClient. Here is the code: TTaskClientTCP = Class( TWSocketThrdClient ) public Buffer : String; ConnectTime : TDateTime; end; procedure TTaskServerTCP.Internal_ClientCreated(Sender: TObject; Client: TWSocketClient); begin Client.OnDataAvailable := InternalEvent_ClientDataReceived; end; procedure TTaskServerTCP.Internal_ClientConnected(Sender: TObject; Client: TWSocketClient; ErrCode : Word); begin TTaskClientTCP(Client).ConnectTime := now; end; procedure TTaskServerTCP.InternalEvent_ClientDataReceived(Sender: TObject; ErrCode: Word); begin if ErrCode = 0 then begin TTaskClientTCP( Sender ).Buffer := TTaskClientTCP( Sender ).ReceiveStr; Internal_ProcessClientData(TTaskClientTCP( Sender ) ); end; end; two situations might happen: 1) Administrator must shutdown the server. During this shutdown I would like to send a msg to all clients and disconnect them gracefully. 2) A specific client software that is used by a single power user can request a server restart. I would like to send a command to all the clients that a restart has been requested. The restart should disconnect all clients, wait a few seconds, and reconnect again. In my current implementation, this is still not implemented. If the server shuts down with live clients, bad things happens to the client side. The only option, is to disconnect all the clients (one by one), then disconnect the server. If the latter is done, the application can be used without any problems. What would be the safer way to implement this shutdown? Should the server call a DisconnectAll, or should the server send a message to the client, and wait till all the clients are offline. Is there any sample of such procedure? Best regards, Clément -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Newbie question : Working with Long strings
Hello Wilfried, Thanks for helping me! Hello Clément, I searched some examples, but most of them use LineMode and LineLimit. I'm afraid that's not an option. Wy is that not an option ? What is the problem with it ? Just terminate your data with a charcter that cannot be in the data itself and your whole problem is solved. Ok. But can I place a LineLimit over 200kbytes? or better yet, unlimited? (those help files can get very big may be over 1Mb) Can I set the LineLimit at runtime at any time? Where/when should be the correct place to update LineLimit? For example, once I check the data length is larger then the limit, then I add a few more bytes, save this new limit in a .ini for example. Best regards, Clément -- 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] Newbie question : Working with Long strings
Hi, I am using D7 and ICS v5 on a Server / Client project. The client can send something like : 100 REQUEST HELP {somecommand} and the server can answer with a small text, or a large one. In my example, there's a 104 kbytes file. Not very large, but large enough to trigger several DataAvailable events. I searched some examples, but most of them use LineMode and LineLimit. I'm afraid that's not an option. So I wrote the following code, but I'm still lost: procedure TMyClient.Event_DataAvailabe( Sender : TObject; Error : Word ); const BufSize = 4096; var zBuf : Array[0..BufSize-1] of Ansichar; Len : Integer; begin { Remember: we use line mode. We will always receive complete lines } with Sender as TWSocket do Len := Receive(@zBuf, BufSize ); // here I expect Len = BufSize. If it's equal than may be there's more to // read. How can I be sure? Does ICS have some internal flag ? if Len = 0 then begin // Something happened!! What? Exit; end; if Len=-1 then begin // Seems to be the end of a long string. Once len = -1, can // this event be fired again? exit end; // Now the problem: // I must cache the received zBuf FRcvBuf := FRcvBuf+ string(zBuf); // If we read all the data, we display it if {Some condition met} then begin DisplayMemo.Lines.Add(FRcvBuf ); FRcvBuf := ''; end; end; Am I on the right track? Can somebody help me? TIA, Clément -- 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