I am working with sockets in C (linux) and I need to send a bit longer text (60characters) over the network. I’ve tried a char pointer, but it is too short. Any suggestions what should I use?
char *data = "A lot of text....";
...
if (send(new_fd, data, 13, 0) == -1)
perror("send");
I’m not really a c person, so what does that number 13 mean?
This is how you should send the data.
From the manual:
So the
13is the number of bytes sent.One thing to consider is that
send(2)doesn’t guarantee it will be able to send all of it in one go. You need to loop and check how much it wrote. A good way to do it is using thewritenfunction of Stevens.