【UNP_socket编程】初识socket、bind、listen、connect、accept、close

文章目录1.基本TCP客户/服务器程序的套接字函数2.socket函数3.bind函数4.listen函数5.connect函数6.accept函数7.close函数1.基本TCP客户/服务器程序的套接字函数2.socket函数 #include<sys/socket.h> int socket(int family, int type, int protocol); //...
摘要由CSDN通过智能技术生成

1.基本TCP客户/服务器程序的套接字函数

在这里插入图片描述

2.socket函数
	#include<sys/socket.h>
	int socket(int family, int type, int protocol);
	//return 0 when success ,otherwise -1
	listenFd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);

  • socket函数创建一个未绑定ip和端口的套接字。
3.bind函数
	#include<sys/socket.h>
	int bind(int sockfd, const struct sockaddr* myaddr, socklen_t *addrlen);
	//return 0 when success ,otherwise -1
  • bind函数将套接字绑定到指定的地址myaddr上
4.listen函数
	#include<sys/socket.h>
	int listen(int sockfd, int backlog);
	//return 0 when success ,otherwise -1
  • 内核为监听套接字维护两个队列:未完成连接和已完成连接队列。backlog指明了两个队列中连接数之和的上限
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值