Working with C socket received data

Asked

Viewed 68 times

0

I have a script that receives data via socket done in C, and I’m having difficulty working with this data.

Data received from customer: "Imei:123123,23123,tracker,0.0......".

I need to receive this data and give a type of explode to each "," same model used by PHP.

The excerpt from the code I’m struggling with...

while(client_size = recv(fd, msgin, sizeof(msgin), 0) != 0){

    //log
    myfile.open ("x.log",ios::app);
    myfile << put_time(localtime(&t), "%c") << " Data: " << msgin << endl;
    myfile.close();

    //------A intenção seria essa------------

    char *text = explode(msgin,',');
    .............
    ..........

    memset(msgin, 0, sizeof(msgin)); //Limpa o buffer
}

How to proceed??

1 answer

-1

Use the function Strtok of <string.h>. It breaks a string into several tokens, based on certain characters. More information on: Strtok

Browser other questions tagged

You are not signed in. Login or sign up in order to post.