网络与主机字节转换函数:htons ntohs htonl ntohl
摘要:网络与主机字节转换函数:htons ntohs htonl ntohl 网络字节序: 网络字节顺序是TCP/IP中规定好的一种数据表示格式,它与具体的CPU类型、操作系统等无关,从而可以保证数据在不同主机之间传输时能够被正确解释。网络字节顺序采用big endian(大端)排序方式。 注:网络字节序
阅读全文
posted @
2020-04-03 17:38
不留念
阅读(380)
推荐(0)
套接字socket
摘要:基本概念 套接字(Socket)是一种介于应用层与传输层之间的抽象层,使用Socket可以将应用程序添加到网络中,并可以与处于同一个网络中的其他应用程序进行数据通信。 sockect一定要有IP地址跟端口号: IP地址:在网络环境中唯一标识一台主机 端口号:在主机中唯一标识一个进程 IP地址+端口号
阅读全文
posted @
2020-04-03 17:33
不留念
阅读(279)
推荐(0)
网络编程中的read函数跟write函数
摘要:read()函数 作用: 用于从文件描述符对应的文件读取数据(从打开的设备或文件中读取数据)。 read()会把参数fd所指的文件传送count 个字节到buf 指针所指的内存中。 头文件: #include<unistd.h> 函数原型: ssize_t read(int fd,void*buf,
阅读全文
posted @
2020-04-03 17:26
不留念
阅读(999)
推荐(0)
简单的tcp服务端/客户端代码例二
摘要:客户端: //客户端连接上服务器之后就会收到服务器的回送信息 #include<stdio.h> #include<sys/socket.h> #include<stdlib.h> #include<arpa/inet.h> #include<unistd.h> #include<string.h>
阅读全文
posted @
2020-04-03 15:49
不留念
阅读(241)
推荐(0)
简单的tcp服务端/客户端代码例一
摘要:客户端:(client1.c) 1 include<unistd.h> 2 #include<stdlib.h> 3 #include<sys/socket.h> 4 #include<arpa/inet.h> 5 #include<string.h> 6 7 #define BUFSIZE 102
阅读全文
posted @
2020-04-03 15:44
不留念
阅读(272)
推荐(0)
创建一个简单TCP的c/s模型服务器用到的基本函数
摘要:connect() 作用: 将套接字连接到目的地址,客户端通过调用connect函数来建立与TCP服务器的连接。简单的说就是用来连接服务器。头文件: #include<sys/socket.h>函数原型: int connect(int sockfd, const struct sockaddr *
阅读全文
posted @
2019-12-21 22:41
不留念
阅读(615)
推荐(1)