I have a client and a server. I use UDP. (C/Unix)
In server I do have a structure:
typedef struct Header {
int seqid;
int len;
char payload[100];
}
...
char test[100];
struct Header package;
package.seqid = 1;
package.len = 64;
strcpy(package.payload, test);
sendto(sockfd, &package, 100, 0, (struct sockaddr*)&cliaddr, sizeof(cliaddr));
In client I do have the same structure:
struct Header* myrepos;
...
recvfrom(sockfd, recvline, 100, 0, NULL, NULL);
//recvline is a char[100]
...
I want to load into the “myrepos” the submitted structure (submitted by server).
How can I do that?
Using a
*angel = (struct Header*)&recvline;
result in compiler errors.
I am not sure if my methid is quite right or it can happen.
Are there other solutions?
Thank You!
If you want to send fixed size packages. Then this could be the solution:
Server:
Client:
Of cource you must check return codes of functions.
If you want to send variable sized packages, it would be more complex.