I must admit i am lost, or at least confused.
When i am using TCP with sock_stream the protocol does not limit the messages (thats what i understood) so if i send a stream with let say
[int][int] [[int][int][int]]*
where the first would be the type of message, the second would be the size of the last "chunk", hipoteticaly a string converted in a array of ints.
so lets say the message is:
Code:
//one side
int msg[] = {101,3,123,321,123};
if(send(sock,msg,sizeof(int)*5,0)<0)ERR("Error while sending...\n");
now my question is, on the other side, since this is a stream, can i do:
Code:
int type;
if(recv(sock,&type,sizeof(int), 0)<0)ERR("Dint recieve type of message...\n");
if(type==101)somefunction();
void somefunctio(){
int size,*data;
data=(int*)malloc(sizeof(int));
if(recv(sock,&size,sizeof(int), 0)<0)ERR("Dint recieve size of data...\n");
data=(int*)realloc(data,sizeof(int)*size);
if(recv(sock,data,sizeof(int)*size,0)<o)ERR("dint recieve data...\n");
}
so can i use lots of recv to subdivide the info i sent? like on the exemple above, i send 1 message but use 3 recv to treat it, one for the type, one for the size and one to get the data (since now i know the size).
If this is not possible is there another way to do it? i cant send alot of messages so i would need to use something like describe above.
Thanks
Rykaerdoe <(^.^<)