Code Monkey home page Code Monkey logo

linuxnet's Introduction

Linux 网络编程

黑马程序员Linux网络编程学习笔记。主要说明每个c文件是什么作用,需要复习去看代码就行了。

tcpsocket文件夹

1.tcpserver.c

​ tcp服务器端设计

2.tcpserver1.c

​ 同tcpserver.c.

cfd =accept(lfd,(struct sockaddr *)&clit_addr,&clit_addr_len);唯一的区别就是在这边可以获得客户端的网络地址,ip+port,然后读取的方法如下

 50     printf("client ip=%s,port=%d\n",
 51             inet_ntop(AF_INET,&clit_addr.sin_addr.s_addr,cliet_ip,sizeof(cliet_ip)),
 52             ntohs(clit_addr.sin_port));

可以看到ip地址的获取方法利用inet_ntop,port利用ntohs。

3.tcpclient.c

​ 我自己写的错误版本客户端实现。

4.tcpclient1.c

​ 正确版本的客户端实现,值得注意的是在tcpserver.c/tcpserver1.c中,

​ serv_addr.sin_addr.s_addr=htonl(INADDR_ANY);服务器端地址利用本地可用的任意地址

但是在客户端中,连接只能连接确定的服务器地址 ,所以需要做转换。

​ ret = inet_pton(AF_INET,"127.0.0.1",&serv_addr.sin_addr.s_addr);

linuxnet's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.