C # Network programming (Basic concepts and operations)

Source: Internet
Author: User
Tags file upload socket string back port number

Introduction

C # Network programming series of articles plan to simply describe the basic knowledge of network programming, because I have limited ability in this area, so I can only provide some initial knowledge, I hope to learn from the first friends to provide some help. If you want more in-depth content, you can refer to the relevant books.

This article is the first of the series, mainly on the basis of socket (socket) for network programming basic concepts, including TCP protocol, socket, chat program three development modes, and two basic operations: Listening port, connecting remote server; the second one tells a A simple example: transferring strings from the client to the server, the server receives and prints the string, converts the string to uppercase, and then sends the string back to the client, which is the last time the client prints the string that was returned; the third is an intensification of the second one, which tells of a problem not addressed in the second article, and using asynchronous transmission to complete the same function as the second, and the fourth shows how to send and receive files between the client and the server; The fifth article realizes a chat program that can chat online and file transfer, in fact, it is a comprehensive application to the prior knowledge.

Related to this article is another article is: C # to write a simple chat program, but this chat program is not as powerful as the chat program in this series, the implementation of the same way.

Basic concepts of Network programming

1. Connection-Oriented transport protocol: TCP

For the TCP protocol I don't want to say too much, it's a college course, and it's a computer science, and I'm not a "college student," and for this part, I think as a developer, I just need to master the concepts related to the program and don't need to do too much research.

We first know that TCP is connection-oriented, it means to say that two remote hosts (or processes, because, in fact, remote communication is the communication between processes, while processes are running programs), you must first perform a handshake to confirm that the connection succeeds before transferring the actual data. For example, process A wants to send the string "It ' s a fine day" to process B, which first establishes the connection. In this process, it first needs to know the location of process B (host address and port number). Then send a request message that does not contain the actual data, we can call this message "Hello". If process B receives this "Hello", it responds to process a "hello", and process a then sends the actual data "It's a Fine Day".

The second thing you need to know about TCP is that it's full-duplex. This means that if a process (such as process a, process B) on two hosts is established, the data can flow from a to B or B to a. In addition, it is point-to-point, meaning that a TCP connection is always between the two, in the sending, through a connection to send data to multiple receivers is not possible. TCP also has a feature, is called reliable data transmission, meaning that the connection is established, the data sent must be able to arrive, and is orderly, that is, when you send the ABC, then the receiving party must be ABC, and not BCA or anything else.

One of the most important concepts associated with TCP in programming is sockets. We should know the network Seven layer protocol, if we put the above application, presentation layer, session layer as a general level (some of the teaching material is so divided), then we write the Web application is located in the application layer, and we know that TCP is a Transport layer protocol, So how do we use the transport layer's services at the application level (message sending or file upload downloads)? We know that in the application we use the interface to separate the implementation, between the application layer and the transport layer, the socket is used to separate. It's like the transport layer is a small opening for the application layer, the application sends the data remotely through this small port, or receives the data from the remote, and the small mouth, that is, after the data enters the mouth, or the data comes out of the mouth, we do not know or need to know, we do not care how it transmits, This is part of the network's other level of work.

For example, if you want to send an e-mail to a friend far away, then how do you write letters, the letter packaging, belong to the application layer, the letter how to write, how to pack entirely by our decision; and when we put the letter into the mailbox, the mailbox that mouth is socket, after entering the socket, is the transport layer, network layer, etc. (Post Office, The other level of work of the highway, such as pipe or route. We never care about how the letter was sent from Xi ' An to Beijing, we just know that it's OK to put it in the mailbox. You can use the following two graphs to represent it:

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.