0

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?

PTN
  • 1,658
  • 5
  • 24
  • 54
  • 3
    already answered in [stack overflow](http://stackoverflow.com/questions/11147633/send-and-receive-an-integer-value-over-tcp-in-c) – BEPP Aug 17 '15 at 04:55

2 Answers2

2

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.

Community
  • 1
  • 1
Haris
  • 12,120
  • 6
  • 43
  • 70
1

Yes, you are allowed to pass an array of ints 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.

Community
  • 1
  • 1
user156213
  • 736
  • 4
  • 12