简体   繁体   中英

Indy TCP/IP Server with Client using Chilkat Library

Im currently trying to use my Client with a Chilkat library since the Client has to be written in Visual C++ and not Borland C++(C++Builder). Connecting does work but as soon I try to send a string from the Client to the Server it doesn't even hit the IdTCPServerExecute Function. Is it even possible to use another library for the Client than the Server is using? If so, how?

Edit: I got it working that the Client successfully sends a string to the server. I now handle the Client message like this:

UnicodeString Message = AContext->Connection->Socket->AllData();

Instead of:

UnicodeString Message = AContext->Connection->Socket->ReadLn();

Now is there a simliar option to send the response string from the server?

        if (IdHTTP->Get
            ("http://*/index.php?option=com_bookpro&controller=customer&task=bpajaxlogin&username=" +
            slTokens->Strings[1] + "&password=" + slTokens->Strings[2] +
            "&product_id=" + Class) == "true") {
            AddLog("1");
            char* Response = "Test";
            AContext->Connection->Socket->Write(Response);
            AddLog("2");
        }
        else {
            AContext->Connection->Socket->WriteLn
                ("Authentication failed");

        }

It also only comes to AddLog("1"); and does not display AddLog("2"); .

Client Code(using Winsocks for tests atm.):

recv(ConnectSocket, recvbuf, recvbuflen, 0);
printf("Bytes received: %d, %s\n", sizeof(recvbuf), recvbuf);

Im currently trying to use my Client with a Chilkat library since the Client has to be written in VCL C++ and not Borland C++(C++Builder).

What is "VCL C++" compared to "Borland C++"? Are you referring to Borland's command-line compiler, as opposed to the C++Builder compiler? Or are you referring to a completely different third party VCL framework that has nothing to do with Borland's VCL framework in C++Builder? Please clearify your question.

Connecting does work but as soon I try to send a string from the Client to the Server it doesn't even hit the IdTCPServerExecute Function.

That is hard to explain without seeing your actual server code.

TIdTCPServer creates a new thread for each connected client. The TIdTCPServer::OnExecute event is not tied to actual network activity, it simply triggers in an endless loop for the lifetime of each thread. The only way the OnExecute event would not be triggered at all is if either:

  1. you are deadlocking the thread in the TIdTCPServer::OnConnect event, such as by doing something that is not thread-safe. Or, you are doing something to cause an exception to be thrown and you are not catching it. An uncaught exception will terminate the thread.

  2. the client disconnects while the TIdTCPServer::OnConnect event handler is still running, or in between the time after the event handler exits and before the TIdTCPServer::OnExecute event handler is called for the first time.

Is it even possible to use another library for the Client than the Server is using?

Of course it is possible. TCP is a standardized transport protocol. As long as different TCP implementations adhere to the standard, they can communicate with each other without problem. This is fundamental to stable communications across multiple platforms, and the Internet relies on this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM