C++ Client - reqInternalError when creating a match

Greetings,

I’m working on getting a barebones C++ client set up so I can begin experimenting with Game design.

I’m running into some trouble creating a match. Below you can see the output of my program. I am successfully authenticating and starting a session. I can even ask the server to return my User ID and User Name.

I connected the rtclient and set the listener using the code snippet documented here: C++ - Heroic Labs Documentation

Then I call my “create match” function which copies from the code here.
The error reads: [NRtClient::reqInternalError] NRtError: CONNECT_ERROR

I’m not sure what I’m doing wrong. I think this is a client side problem because I tried calling my “create match” function again after I’ve ended the tick and I get the same error.

Can anybody help? Any input is much appreciated.

Hey @Mehoo462 the most likely explanation is that you are trying to send over a socket that is not yet connected.

How are you composing your connect() and createMatch calls?

Hi @lugehorsam!

I’m not sure what you mean by “connect()” call. Are you referring to “rtclient->connect().” If so, I followed the example here. I copied that block into the start function of my session object, so it gets called right after authentication.

My session object has a start function which I call in main. The start function authenticates and then creates the realtime client. Below is the code pertaining to the realtime client. I’m pretty sure this code is getting executed because the logger reports
[NRtClient::NRtClient] Created
NRtClient::NRtClient] using default port 7350
[NrtClient::connect] …
[NWebSocketCppRest::connect] …
and then when the program closes: [NWebSocketCppRest::disconnect]


// Set up the RealTime Client and listener
        rtClient = _client->createRtClient();
        listener.setConnectCallback([]()
            {
                cout << "Socket connected." << endl;
            });
        rtClient->setListener(&listener);
        rtClient->connect(_session, createStatus);

My session object also has a function to create a match which I copied from here.


//A function to create a match
    void createMatch() {
        rtClient->createMatch([](const NMatch& match)
            {
                std::cout << "Created Match with ID: " << match.matchId << std::endl;
            });

This code gets called in my main function by:

MySession.createMatch();

Is there something else I need to do to connect a socket? I thought “rtClient->connect(_session, createStatus);” was achieving that.

I’ve attached my whole cpp file in case that helps clarify anything (apologies for some of the other newbish things you’ll find in there. This is an exploratory project for me).

Thanks for your input!

Code Sample.txt (5.5 KB)

@Mehoo thanks for sharing. The first issue I see is that you aren’t calling tick() on the realtime client. The second is that I would place the createMatch invocation in the connected callback for the realtime client. That way you can be sure the realtime client has already successfully connected.

Oh I see! You have to call tick on client object and each instance of rtclient.

That’s what these lines are for here

if (rtClient)
                rtClient->tick();

I added those and now I’m getting my match ID back. All is well! :slight_smile:
I will take a look at putting createMatch in the connected callback for additional security.

Thanks!

1 Like