?? socket11_2.c
字號:
/* 發(fā)送方代碼 */
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
char buf[80];
struct sockaddr to_name;
main()
{
int sock, cnt;
sock = socket(AF_UNIX, SOCK_DGRAM, 0);
if (sock < 0) {
printf("socket failure %d\n", errno);
exit(1);
} /* 建立套接字 */
to_name.sa_family = AF_UNIX;
strcpy(to_name.sa_data, "/tmp/tsck");
strcpy(buf, "test data line"); /* 將需要發(fā)送的數(shù)據(jù)添加到緩沖區(qū) */
cnt = sendto(sock, buf, strlen(buf), 0, &to_name,
strlen(to_name.sa_data) + sizeof(to_name.sa_family));
/* 調(diào)用sendto()發(fā)送數(shù)據(jù) */
if (cnt < 0) {
printf("sendto failure %d\n", errno);
exit(1);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -