I'm trying to use Synapse(TTCPBlockSocket) instead of Indy,but through the official help and demo i can't understand how to get the number of TCP client,and i didn't found the connect/disconnect events about Synapse,please give me some hint or sample code. Thanks in advance !
Asked
Active
Viewed 1,437 times
3
-
2At the server side each connection you accept should fire the [`OnStatus`](http://synapse.ararat.cz/doc/help/blcksock.TBlockSocket.html#OnStatus) event with the [`HR_Accept`](http://synapse.ararat.cz/doc/help/blcksock.html#THookSocketReason) reason. However for disconnection or current client count I couldn't find any property or event since each client should run as a separate thread. – TLama May 29 '12 at 10:58
-
2To detect client disconnect, either the data exchange protocol should provide a 'bye!'m 'quit' or 'disconnect' message. The server can also send heart-beat messages to the client if the protocol allows it. – mjn May 29 '12 at 13:19
-
Not a direct answer but you may try ICS (TWSocket and TWSocketServer) with a lot of examples, mainly one of a TCPServer where you can see the numbers of connected clients and the information when a new client is connected. – philnext May 29 '12 at 14:52
-
What do you mean "number of client"? Do you want the IP-address of the server, or the number of connections to the server? – Stijn Sanders May 30 '12 at 14:23
-
@StijnSanders,I want to get number of connections. :) – PFeng Jun 01 '12 at 06:18
1 Answers
2
As TLama notes in the comments, each incoming connection shuold fire the OnStatus event with HR_Accept
. If I look over the TBlockSocket source, each disconnect, either by protocol or by error, should fire an OnStatus event with the HR_SocketClose
reason on the connection socket.

Stijn Sanders
- 35,982
- 11
- 45
- 67
-
To be honest, I haven't been using synapse for a while, after using Indy and Synapse, I've switched back to Delphi's own TTcpClient/TTcpServer in blocking mode and my own thread management, see here for an example: http://xxm.svn.sf.net/viewvc/xxm/trunk/Delphi/http/xxmHttpMain.pas – Stijn Sanders Jun 01 '12 at 07:54
-
+1, the `OnStatus` event with `HR_Accept` reason you'll get only when you accept the incoming connection. But you can still decline it. So if you need to be notified about incoming connection, you'll get it in the listening socket thread context. – TLama Jun 01 '12 at 08:23