Пример #1
0
TcpServer::~TcpServer() {
    qDebug() << Q_FUNC_INFO;

    while (!clientConnections.isEmpty()) {
        TcpClient *client = clientConnections.takeLast();
        client->disconnect(this);
        delete client;
    }
}
Пример #2
0
TcpServer::~TcpServer() {
    DEBUG;

    while (!clientConnections.isEmpty()) {
        TcpClient *client = clientConnections.takeLast();
        client->disconnect(this);
        delete client;
    }
}
Пример #3
0
int _tmain(int argc, _TCHAR* argv[])
{
    TcpClient client;

    TcpSocketCallback_t callback;
    callback.fn_recv   = recvData;
    callback.fn_notify = netNotify;
    callback.usrData   = NULL;
    client.setCallback(callback);

    InetAddress serverAddr("127.0.0.1", 58888);
    client.connect(serverAddr);

    connEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
    while (!connectServer) {
        WaitForSingleObject(connEvent, INFINITE);
        if (reconnect) {
            client.connect(serverAddr);
        }
    }

    int i = 60;
    while (i > 0) { 
        i--;
        Sleep(1000);
        string msg = "hi, I am client";
        client.send(msg.c_str(), msg.size());
    }

    client.disconnect();
    if (connEvent) {
        CloseHandle(connEvent);
        connEvent = NULL;
    }
    return 0;
}