2 #include <SocketHandler.h>
3 #include <ListenSocket.h>
9 virtual bool OnConnectRetry();
10 - void SetRetryClientConnect(bool x = true);
11 - bool RetryClientConnect();
12 void SetConnectionRetry(int n);
13 int GetConnectionRetry();
14 void IncreaseConnectionRetries();
15 int GetConnectionRetries();
16 void ResetConnectionRetries();
18 class RetrySocket
: public TcpSocket
21 RetrySocket(ISocketHandler
& h
) : TcpSocket(h
) {
23 SetConnectionRetry(-1);
26 bool OnConnectRetry() {
27 printf("Connection attempt#%d\n", GetConnectionRetries());
28 if (GetConnectionRetries() == 3)
30 ListenSocket
<RetrySocket
> *l
= new ListenSocket
<RetrySocket
>(Handler());
33 printf("Bind port 12345 failed\n");
35 l
-> SetDeleteByHandler();
42 printf("Connected\n");
43 printf("GetRemoteAddress(): %s\n", GetRemoteAddress().c_str());
44 printf("Remote address: %s\n", GetRemoteSocketAddress() -> Convert(false).c_str());
45 printf("Remote address: %s\n", GetRemoteSocketAddress() -> Convert(true).c_str());
55 int main(int argc
, char *argv
[])
59 sock
.Open("localhost", 12345);