mirror of
https://github.com/riba2534/TCP-IP-NetworkNote.git
synced 2026-04-13 18:00:00 +08:00
完成第一章 理解网络编程和套接字
This commit is contained in:
22
ch01/fd_seri.c
Normal file
22
ch01/fd_seri.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int fd1, fd2, fd3;
|
||||
//创建一个文件和两个套接字
|
||||
fd1 = socket(PF_INET, SOCK_STREAM, 0);
|
||||
fd2 = open("test.dat", O_CREAT | O_WRONLY | O_TRUNC);
|
||||
fd3 = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
//输出之前创建的文件描述符的整数值
|
||||
printf("file descriptor 1: %d\n", fd1);
|
||||
printf("file descriptor 2: %d\n", fd2);
|
||||
printf("file descriptor 3: %d\n", fd3);
|
||||
|
||||
close(fd1);
|
||||
close(fd2);
|
||||
close(fd3);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user