I'm trying to send an encrypted message in a simple server-client chat program.
This is the send()
call:
int send(int sockfd, const void *msg, int len, int flags);
Can I pass an int
array as *msg
?
I'm trying to send an encrypted message in a simple server-client chat program.
This is the send()
call:
int send(int sockfd, const void *msg, int len, int flags);
Can I pass an int
array as *msg
?
I think you can use the send()
system call. But be aware, that the len
is the length of the message in bytes. So i think for an array of 5 int
. You need to specify the len
as 5*(sizeof(int))
.
Additionally, on the receiving side, you need to interpret it accordingly.
As Naveen pointed out, a more detailed answer to your question is already present here.
Yes, you are allowed to pass an array of int
s to send()
. The reason you're allowed to do that is arrays are automatically converted to pointers when they are passed to functions. See this previous question.
In addition, any pointer in C is can be automatically cast to void *
if necessary. Void pointers were designed to provide implicit conversion.