Archived Forum Post

Index of archived forum posts

Question:

CkSocket Receive method not receiving bytes, however Wireshark shows differently..

Dec 22 '16 at 08:11

Hello, I'm currently in a bit of a problem.

I'm trying to simply connect to a hostname/port provided and receive the string "pong" upon connecting and after sending "pingservice".

It seems to never be received and the debug from lastErrorText is extremely vague, even with verboseLogging on:

[2016-12-22 07:43:37] [ok] [PingLoop] Host 1 | Hostname : xx | Port: 2550 | Location: 2
[2016-12-22 07:43:37] [ok] [PingLoop] String sent!
[2016-12-22 07:43:47] [ok] [PingLoop] Couldn't recv. Debug:

ChilkatLog:

Close(31ms):

ChilkatVersion: 9.5.0.64

terminateConnection(31ms):

  TCP connection cleanly closed by peer.

  Cleanly terminated TCP connection.

--terminateConnection

--Close

--ChilkatLog

However. I find this strange since I decided to do a bit of debugging on my own using Wireshark (as it's not a SSL protected connection) and low-behold, the bytes "pong" are in several of the packets coming from the hostname I'm connected to.

http://i.imgur.com/A6oTsSW.png

However, it never seems like Chilkat recognizes this and cannot read the data.

Here is the code snippet provided:

g_Socket.put_VerboseLogging(true);

    for (int i = 0; i < size; i++)
    {
        auto host = hosts.Get(i);

        const char* hostname = host.hostname().c_str();
        int port = host.port();
        Location location = host.location();

        cout << "Host " << i << " | Hostname: " << hostname << " | Port: " << port << " | Location: " << (int)location << endl;
        Log("[PingLoop] Host " + std::to_string(i) + " | Hostname : " + string(hostname) + " | Port: " + std::to_string(port) + " | Location: " + std::to_string((int)location), LogLevelFlags::SUCCESS);

        bool success = g_Socket.Connect(hostname, port, false, 10000);

        g_Socket.put_MaxReadIdleMs(10000);
        g_Socket.put_MaxSendIdleMs(10000);

        if (success)
        {
            auto start = std::chrono::high_resolution_clock::now();
            if (g_Socket.SendString("pingservice"))
            {
                Log("[PingLoop] String sent!", LogLevelFlags::SUCCESS);

                CkByteData byteData;
                if(g_Socket.ReceiveBytes(byteData))
                {
                    Log("[PingLoop] recv", LogLevelFlags::SUCCESS);
                    newLatencies[location] = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start).count();
                    Log("[PingLoop] Took " + std::to_string(newLatencies[location]) + " ms", LogLevelFlags::SUCCESS);
                }
                else
                {
                    g_Socket.Close(TIMEOUT);
                    newLatencies[location] = TIMEOUT;
                    Log("[PingLoop] Couldn't recv. Debug:\n" + string(g_Socket.lastErrorText()), LogLevelFlags::SUCCESS);
                    continue;
                }

What exactly am I doing wrong here? I've tried ReceiveString before, still same result. Receiving doesn't seem to work, but sending does.

Any bit of help would be much appreciated ^^