Networking Programming

Wenzhi Xu

What's the network?

For communication, connection, transmission, etc.

In computer science, Network is PROTOCOLS.

Image from https://www.bmc.com/blogs/osi-model-7-layers/

 OSI is a conceptual model.

In modern Internet, we don't use this model.

BUT, it doesn't mean OSI model is useless.

TCP/IP Model

Image from http://www.cellbiol.com/bioinformatics_web_development/chapter-1-internet-networks-and-tcp-ip/the-tcpip-family-of-internet-protocols/

All layers are interdependent.

Internet Layer

Network Access Layer

Transport Layer

Application Layer

lower level

higher level

Internet Layer

Network Access Layer

Transport Layer

Application Layer

Cient/Browser

Server

When we request a web page.

Networking Programming

Everything is file on Linux. Socket Prgramming in Linux.

Socket is a file. Actually, it's called file descriptor.

TCP and UDP

Image from https://learntechit.com/difference-between-tcp-and-udp/

Write a web server (Like Nginx)

  1. What kind of protocols do we need to use?
  2. Does it need to be reliable when transmitting data?

A Lifecycle of Socket

Create

Bind

Listen

Accept

Create

Read/Write

Close

int socket(int family, int type, intprotocol);
int bind(int sockfd, const struct sockaddr *myaddr, socklen_t addrlen);
int listen(int sockfd, int backlog);
int accept(int sockfd, struct sockaddr *client_addr, socklen_t *len);
ssize_t read(int fs, void *buf, size_t N);
ssize_t write(int fs, const void *buf, size_t N);
int close(int fildes);

Connect

Can we implement a new HTTP protocol based on UDP?

QA

References

https://en.wikipedia.org/wiki/OSI_model

https://www.gnu.org/software/libc/manual/html_node/Sockets.html

https://thenewstack.io/http-3-replaces-tcp-with-udp-to-boost-network-speed-reliability/

Thanks.

networkingprogramming

By xuwenzhi

networkingprogramming

  • 72