Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTcpClientPtr Client Send() returned TRUE, but data cannot be transmitted. #302

Open
mnt-github opened this issue Jan 14, 2025 · 11 comments

Comments

@mnt-github
Copy link

mnt-github commented Jan 14, 2025

Through several tests, i verified that there were no errors in the socket server.

Code is below.

// ClientSocket.h
#include "HPSocket.h"

class ClientSocket : public CTcpClientListener
{
    bool ConnectSocketToServer(const char* szAddress, unsigned short usPort);
    ...
    CTCPClientPtr m_pClient;
    ...
}



// ClientSocket.cpp
#include "ClientSocket.h"

#ifdef WIN64
#ifdef _DEBUG
#pragma comment(lib, "../../HP-Socket-Dev/Windows/Lib/HPSocket/x64/static/HPSocket_D.lib")
#else
#pragma comment(lib, "../../HP-Socket-Dev/Windows/Lib/HPSocket/x64/static/HPSocket.lib")
#endif
#else
#ifdef _DEBUG
#pragma comment(lib, "../../HP-Socket-Dev/Windows/Lib/HPSocket/x86/static/HPSocket_D.lib")
#else
#pragma comment(lib, "../../HP-Socket-Dev/Windows/Lib/HPSocket/x86/static/HPSocket.lib")
#endif
#endif

ClientSocket::ClientSocket()
    : m_pClient(this)
{
}

bool ClientSocket::ConnectSocketToServer(const char* szAddress, unsigned short usPort)
{
    m_pClient->SetSocketBufferSize(MAX_PACKET_SIZE);
    if (!m_pClient->Start(szAddress, usPort))
    {
        return false;
    }
    return true;
}

EnHandleResult ClientSocket::OnReceive(ITcpClient* pSender, CONNID dwConnID, const BYTE* pData, int iLength)
{
    BYTE* pReplyData = NULL;
    DWORD dwReplyDataLen = 0;

    // ... Recv Procession ...

    // Reply Data
    if (!m_pClient->Send(pReplyData, dwReplyDataLen))
    {
        m_pClient->Stop();
    }
}

The data is transmitted the first time, but not again after that.
I defined HPSOCKET_STATIC_LIB at Project Property Page -> C/C++ -> Preprocessor -> Preprocessor Definitions.

Please, Help me.

@ldcsaa
Copy link
Owner

ldcsaa commented Jan 14, 2025

m_pClient->Start(szAddress, usPort) is async connect by default.
Data can only be sent after receiving the OnHandShake event.

@mnt-github
Copy link
Author

mnt-github commented Jan 14, 2025

// ClientSocket.cpp

EnHandleResult ClientSocket::OnConnect(ITcpClient* pSender, CONNID dwConnID)
{
    // try to authenticate
    BYTE auth_packet[AUTH_PKT_LEN] = { 0 };
    ....
    if (!m_pClient->Send(auth_packet, AUTH_PKT_LEN))
    {
        m_pClient->Stop();
        return HR_OK;
    }
}

AUTH_PKT_LEN is 40 bytes. Only Auth data is transmitted.
After this, any data is not transmitted.

m_pClient->Send() always returned TRUE.

@ldcsaa
Copy link
Owner

ldcsaa commented Jan 14, 2025

Use system ::GetLastError() to get error.

and if OnSend event fired, means that send ok.

@mnt-github
Copy link
Author

Use system ::GetLastError() to get error

::GetLastError() returned 0.

@ldcsaa
Copy link
Owner

ldcsaa commented Jan 14, 2025

OnSend event triggered?

@mnt-github
Copy link
Author

OnSend event triggered?

Yeah, When first AUTH data is transmitted, OnSend event triggered.
After then, not triggered.

Previously, when I developed by loading the source code of HPSocket, Data communication worked properly.
There are too many include errors when loading the gdiplus library, so i had changed HPSocket Static Library.
From then on, this problem occurred.

@ldcsaa
Copy link
Owner

ldcsaa commented Jan 14, 2025

try dynamic library ...

And the include files version must match the library version.

What's HP-Socket version ?

@mnt-github
Copy link
Author

try dynamic library ...

And the include files version must match the library version.

What's HP-Socket version ?

Sorry, How can i check HP-Socket version?

@ldcsaa
Copy link
Owner

ldcsaa commented Jan 14, 2025

version defined in HPTypeDef.h
or

// 获取 HPSocket 版本号(4 个字节分别为:主版本号,子版本号,修正版本号,构建编号)
HPSOCKET_API DWORD HP_GetHPSocketVersion();

@mnt-github
Copy link
Author

version defined in HPTypeDef.h or

// 获取 HPSocket 版本号(4 个字节分别为:主版本号,子版本号,修正版本号,构建编号)
HPSOCKET_API DWORD HP_GetHPSocketVersion();

In HPTypeDef.h, version defined as 6(Major).0(Minor).1(Revise).6(build)
And HP_GetHPSocketVersion() returned 100663558.
100663558 is correct?

@ldcsaa
Copy link
Owner

ldcsaa commented Jan 14, 2025

@mnt-github correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants