Quantcast
Channel: Chilkat Forum - latest questions
Viewing all articles
Browse latest Browse all 1061

How to do simultaneous CkSocket_AcceptNextConnection

$
0
0

Hi,

Is it the right way and the best way to do an infinite loop wich accepts simultaneaous incoming connections in a server ?

It seems to crash with the non-blocking (asynchrounous) solution. That's why I am going to try with the blocking solution because the receive phase wich follows is in a thread

Best regards

Thanks

This the simplified code :

    if (!CkSocket_UnlockComponent(listenSocket,"mycode....")) 
     goto label_endloop ;

if (!CkSocket_BindAndListen(listenSocket,5001,32)) 
        goto label_endloop ;

label_startloop :

if (byChilkat == 2) // NOT BLOCKING
    {

task = CkSocket_AcceptNextConnectionAsync(listenSocket,0);
        if (CkSocket_getLastMethodSuccess(listenSocket) != TRUE) 
        {   ShowError ("Error CkSocket_AcceptNextConnectionAsync :", (char *)CkSocket_lastErrorText(listenSocket), FALSE) ;
            goto label_startloop ;
        }

if (!CkTask_Run(task)) 
        {    ShowError ("Error CkTask_Run (CkSocket_AcceptNextConnectionAsync) :", (char *)CkSocket_lastErrorText(listenSocket), FALSE) ;
            CkTask_Dispose(task);
            goto label_startloop ;
        }

while (CkTask_getFinished(task) != TRUE) 
            CkTask_SleepMs(task,10);    //  Sleep 10 ms.

status = CkTask_getStatusInt(task) ;
        if (status != 7) 
        {    ShowError ("Task (CkSocket_AcceptNextConnectionAsync) did not complete. Task status: ", (char *)CkTask_status(task), FALSE) ;
            CkTask_Dispose(task);
            goto label_startloop ;
        }

clientSocket = CkSocket_Create();
        if (!CkSocket_LoadTaskResult(clientSocket, task)) 
        {    ShowError ("CkSocket_LoadTaskResult", (char *)CkSocket_lastErrorText(clientSocket), FALSE) ;
            CkTask_Dispose(task);
            goto label_startloop ;
        }

CkTask_Dispose(task);
    }
    else    // BLOCKING
    {
         clientSocket = CkSocket_AcceptNextConnection(listenSocket, 0);
    }

hThreadSocketChilkatC = CreateThread(NULL, 0, ThreadSocketQuestionResponse, (LPVOID)&clientSocket, 0, &dwThreadId);

goto label_startloop ;

label_endloop :

Viewing all articles
Browse latest Browse all 1061

Trending Articles