c/s基础
原型
在上周开发基础上, 完成 极简交互式笔记的网络版本
- 如何进行网络开发?
- 什么是 DUP 协议?
- 用 Python 完成一对最简单的 DUP 服务器/客户端?
什么是BSD Sockets
Berkeley Software Distribution
BSD Sockets is at the session layer. BSD Sockets is not a protocol. It is a user API to allow access to the protocol stack beneath.
http://wiki.treck.com/Introduction_to_BSD_Sockets
Sockets API
The Sockets API makes use of two mechanisms to deliver data to the application level: ports and sockets.
This is why the term socket is used - it is the connection mechanism between the outside world (the ports) and the application. A common misunderstanding is that sockets-based systems can only communicate with other sockets-based systems. This is not true. TCP/IP or UDP/IP communications are handled at the port level - the underlying protocols do not care what mechanisms exist above the port. Any Internet host can communicate with any other, be it Berkeley Sockets, WinSock, or anything else. "Sockets" is just an API that allows the programmer to access Internet functionality - it does not modify the manner in which communications occur. Let us use the example of an office building to illustrate how sockets and ports relate to each other. The building itself is analogous to an Internet host. Each office represents a port, the receptionist is a socket, and the business itself is an application. Suppose you are a visitor to this building, looking for a particular business. You wander in, and get directed to the appropriate office. You enter the office, and speak with the receptionist, who then relays your message to the business itself. If there is nobody in the office, you leave. To rephrase the above in sockets terminology: A packet is transmitted to a host. It eventually gets to the correct port, at which point the socket conveys the packet's data to the application. If there is no socket at the destination port, the packet is discarded.
什么是UDP协议
http://wiki.treck.com/Introduction_to_TCP/IP#The_User_Datagram_Protocol_.28UDP.29
Socket Programming HOWTO
important thing to understand now is this: this is all a “server” socket does. It doesn’t send any data. It doesn’t receive any data. It just produces “client” sockets.