网络编程
本文目录 17 个章节
网络编程
创建时间:2021/6/6 21:21
- 网络编程
- 基础知识
- Terms
- Server
- Host
- Client
- The Internet Protocols: TCP, UDP, And IP
- The application layer & The transport layer
- The network layer
- Summary
- Network Client-Server Applications
- TCP/IP Sockets
- Introduction
- types of sockets in TCP/IP
- Socket Implementation in .NET
- Terms
- 实践应用
- 经验
- Ref
- 基础知识
基础知识
Terms
The terms server and client each have both a hardware and software aspect.
Server
The term server is often used to refer both to a piece of computing hardware on which a server application runs and to the server application itself. A good definition for a server then is any computer used to host one or more server applications as its primary job.
Host
A server running a server application is also referred to as a host. The term host extends to any computer running any application.
Client
The term client is also used to describe both hardware and software. Client hardware is any computing device that hosts an application that requires or uses the services of a server application. Client software is any application that requires or uses the services provided by a server application.
The Internet Protocols: TCP, UDP, And IP

图片来源:C# FOR ARTISTS The term packet-switched network means that data traveling along network pathways is divided into small, routable packages referred to as packets. If a communication link between two points on a network goes down, the packets can be routed through remaining network connections to their intended destination.
The Internet protocols work together as a layered protocol stack. The layered protocol stack consists of the application layer, the transport layer, the network layer, the data link layer, and the physical layer. Each layer in the protocol stack provides a set of services to the layer above it.
Putting it all together:

The application layer & The transport layer
The application layer represents any Internet enabled application that requires the services of the transport layer. The purpose of the transport layer is to provide host-to-host, connection-oriented, data transmission service to the application layer.
Two Internet protocols that function at the transport layer include the Transmission Control Protocol(TCP) and the User Datagram Protocol (UDP). TCP guarantees data delivery and saves you the worry. UDP is faster than TCP but unreliable.
The network layer
The network layer is responsible for the routing of data traffic between Internet hosts. The Internet Protocol (IP) is a connectionless service that permits the exchange of data between hosts without a prior call setup. (Hence the term connectionless.) It packages data submitted by TCP or UDP into blocks called datagrams. IP uses IP addresses and routing tables to properly route datagrams to their intended destination networks.
Summary
Computers that participate in a TCP/IP networking environment must be running an instance of the TCP/IP protocol stack. The TCP/IP protocol stack is part of a computer’s operating system.
Network Client-Server Applications

the three components of a typical .NET remoting application:
a remotable object
a server application that coordinates method calls to the remote object and makes its services available on a particular channel
a client application that accesses the services of the remote object via the appropriate channel.
TCP/IP Sockets
Introduction
A socket is an abstraction through which an application may send and receive data , in much the same way as an open file allows an application to read and write data to stable storage. Information written to the socket by an application on one machine can be read by an application on a different machine.
Different types of sockets correspond to different underlying protocol suites and different stacks of protocols within a suite.
types of sockets in TCP/IP
The main types of sockets in TCP/IP today are stream sockets and datagram sockets.
Stream sockets use TCP as the end-to-end protocol (with IP underneath) and thus provide a reliable byte-stream service.
Datagram sockets use UDP (again, end-to-end with IP underneath) and thus provide a best-effort datagram service that applications can use to send individual messages up to about 65,500 bytes in length.
A TCP/IP socket is uniquely identified by an Internet address , an end-to-end protocol (TCP or UDP), and a port number.

图片来源: TCP/IP Sockets in C#: Practical Guide for Programmers
A port identifies an application on a host
Socket Implementation in .NET

abstraction can sometimes hide some of the flexibility and power of a lower level interface.
In order to allow access to the underlying sockets interface, Microsoft implemented a .NET Socket class, which is a wrapper around the WinSock socket functions and has most of the versatility (and complexity) of sockets interface exposed. Then three higher-level socket classes, TcpClient, TcpListener, and UdpClient, were implemented by using the .NET Socket wrapper class.

实践应用
经验
TCP是可靠传输协议,建立与TCP进行绑定的socket,调用send函数进行数据发送时,同步调用会阻塞,保证数据相连的一端能收到全部数据,才会执行结束。
Ref
C# FOR ARTISTS TCP/IP Sockets in C#: Practical Guide for Programmers