다음과 같이 sendmsg 로 보낸 메시지를 recv 함수를 통해 받을 수 있다.
struct msghdr msg를 이용해 recvmsg를 쓰지 않아도 된다는 것이 확인되었음.
구글 검색으로는 관련 내용이 없는데, 앞으로 이유까지 찾아볼 여유가 있을지 모르겠다.
int SendMsg(int fd, const void *buf, size_t count)
{
struct msghdr msg;
struct iovec iv;
int n;
memset(&msg, 0, sizeof(msg));
iv.iov_base = (void*)buf;
iv.iov_len = count;
msg.msg_iov = &iv;
msg.msg_iovlen = 1;
n = sendmsg(fd, &msg, MSG_NOSIGNAL);
if (n < 0) {
return -1;
}
return 0;
}
#client
SendMsg(client_socket, argv[1], strlen(argv[1])+1);
recv (client_socket, buff, BUFF_SIZE, 0);
printf("receive: %s\n", buff);
#server
recv (client_socket, buff_rcv, BUFF_SIZE, 0);
printf("receive: %s\n", buff_rcv);
SendMsg(client_socket, buff_rcv, strlen(buff_rcv)+1);
'network' 카테고리의 다른 글
| 내부망/외부망 함께 사용 (0) | 2020.04.13 |
|---|---|
| About ping DUP(duplicated) packets (0) | 2019.12.05 |
| iptables 방화벽 설정관련 예제 (0) | 2019.05.13 |
| Cloud gaming (0) | 2019.03.04 |
| NAS SAN 비교 (0) | 2019.03.01 |