Linux C Socket Programming principle and simple example

Source: Internet
Author: User

1. What is TCP/IP,UDP?

2. where is the socket?

3. What is a socket?

4. There are many frameworks, why are you still starting from the socket?

5. Linux C Socket Simple Example

1. What is TCP/IP ,UDP ?

  TCP/IP (transmission Control protocol/internet Protocol) is a protocol/inter-network protocol, an industry-standard set of protocols designed for wide area networks (WANs).
UDP (user Data Protocol, Subscriber Datagram Protocol) is the protocol that corresponds to TCP. It is a part of the TCP/IP protocol family.
The following diagram illustrates the relationship of these protocols.

2.Socket where is it?

3.Socket What is it?

A socket is an intermediate software abstraction layer that the application layer communicates with the TCP/IP protocol family, which is a set of interfaces. In design mode, thesocket is actually a façade mode, it is the complex TCP/IP protocol family hidden behind the socket interface, for the user, a set of simple interface is all, let the socket to organize data to meet the specified protocol.

  Façade mode, in its own words, is the system to provide a single interface to the outside world does not need to understand the internal implementation.

4. There are many frameworks, why are you still starting from the socket?

There are many cross-platform network programming frameworks, such as the ssh,c/c++ boost in Java.

There are many distributed frameworks, such as Hadoop.

My task is to make a C/C + + program distributed, the requirements of the environment, the basic belongs to pure computing, the results are very small. So the socket is selected.

It is important that sockets are the basis for distributed, cloud computing, and network programming, and that learning about sockets facilitates understanding of other frameworks.

Is the basic process of socket programming:

5.Linux C Socket Simple instance with detailed comment

The program is a simple "back-up", the client sends the console input information to the server side, the server returns information as is.

Server-side:

View Code

Client:

View Code

Perform:

Client

Server-side

Linux C Socket Programming principle and simple example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.