linux网络编程学习记录

1.把xmind安装上去,这样方便看思维导图软件


image.png

客户端的程序

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <fcntl.h>

int main(void)
{
    int l_iSocketFd = 0;
    struct sockaddr_in l_stSeverAddr;
    char l_szBuff[100];
    int l_iBytes = 0;

   l_iSocketFd = socket(AF_INET, SOCK_STREAM, 0);

   bzero(&l_stSeverAddr, sizeof(l_stSeverAddr));

   l_stSeverAddr.sin_family = AF_INET;
   l_stSeverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
   l_stSeverAddr.sin_port = htons(8888);

   connect(l_iSocketFd, (struct sockaddr*)&l_stSeverAddr, sizeof(l_stSeverAddr));

   l_iBytes = read(l_iSocketFd, l_szBuff, 100);

   printf("bytes read number:%d\n", l_iBytes);
   printf("Time:%s\n", l_szBuff);
    return 0;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容