美文网首页
linux网络编程学习记录

linux网络编程学习记录

作者: sgy1993 | 来源:发表于2019-02-17 10:21 被阅读0次

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;
}

相关文章

网友评论

      本文标题:linux网络编程学习记录

      本文链接:https://www.haomeiwen.com/subject/izzweqtx.html