Skip to content

[Cute_Net.h] Knowing if a packet has been sent. #367

@SaySayTakamura

Description

@SaySayTakamura

Hello there, my deepest apologies for the bothering, but i came to ask something and maybe suggest something.

I am quite new to this network thing, my apologies if i say or do something wrong.

I walked through the examples and after a while messing with them i went to create a class for both Server and Client and implement on my Debugger project.

Everything was fine until i went to test the client class. It works, but there's something wrong.

Look at this:

Client c;
c.Create(); //Default arguments are (IP: 127.0.0.1 | Port: XXXX) which is Localhost

bool done = false;

while(!done)
{
     c.Process(); //Poll events and updates the client.
     if(c.IsConnected())
     {
       //Following code taken from example
       std::string s = "Still alive";
       c.Send(s); //This functions gets the size of the string and has one version for each type i want to send (such as float, json and some others)

       c.Shutdown();
       done = true;
     }
}
printf("Goodbye <3"); //Shows that the program came to and end.

Ok, the concept for this code is, Create a client, connects to the localhost, sends an string to the server, then disconnect and then end the program.

Now let's go to the server output:

"New client with id (CLIENT ID), connected on index 0"
"Client disconnected on index 0"

Where is the message is the client send?

Problem is, i call to c.Shutdown() and done = true right after "sending" the message, which cancels the next call of c.Process() and with that the message i just sent didn't get processed.

Took me a while to find this out (yup, dumb me), but still something like:

bool cn_client_packet_pending(client)
or bool cn_client_packet_send(client) would be very useful.

Example:

if(cn_client_packet_pending(client) == false)
{
   //Process code go here (c.Process, in my case)
}
else
{
  //Disconnect and close loop to end application
}

The second one would be quite harder to implement, since it would need a server response i suppose, but the first one i think it would be easier to do, i would implement it myself but i don't know how this would work and the nuances behind it.

Well, i think this is it, my deep apologies for the bothering and thanks for reading.

Have a great night.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions