I was searching for hours to get an answer about my question, but didnt find anything. Maybe I get some help here.
What I'm trying to do:
A Java-Client sends a message to a C-Server. The message contains different types like integer, short and also a string (e.g. message = int: total_msg_length; short: operation; string: hello --> total_msg-length=4 (size of integer), operation = 2 (size of short), hello = 5 (each letter is 1 byte=5).
So, how can I receive the message in my server? The code below receives an Integer (works fine). Next step will be to receive a short and then a string (converted in US-ASCII).
int *msg;
int recv_size;
int final_msg;
if( (recv_size = recv(client_socket, &msg, sizeof(msg), 0 )) < 0 ){
error_exit("Fehler bei recv(message_len)");
}
final_msg = endian_swap(msg);
printf("Message: %d
", final_msg);
return final_msg;
Is there a way to use a byte array instead of char buffer? Im thankful for every help. Please excuse my bad english, I'm from germany :-)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…