没有合适的资源?快使用搜索试试~ 我知道了~
首页Network programming with Go(English)
Network programming with Go(English)
5星 · 超过95%的资源 需积分: 10 27 下载量 10 浏览量
更新于2023-03-16
评论 1
收藏 932KB PDF 举报
Network programming with Go 英文版,golang网络编程,有代码,有例子,有解释
资源详情
资源评论
资源推荐
Network programming with Go
v1.0, 27 April 2012 An e-book on building network applications using the Google Go programming language (golang)
This book has been revised to cover Go 1. The book is not complete, and also Go is expected to introduce more packages as it
evolves.
Contents
1. Architecture
2. Overview of the Go language
3. Socket-level Programming
4. Data serialisation
5. Application-Level Protocols
6. Managing character sets and encodings
7. Security
8. HTTP
9. Templates
10. A Complete Web Server
11. HTML
12. XML
13. Remote Procedure Call
14. Network Channels
15. Web Sockets
A PDF is here.
An epub ebook is here.
Copyright © Jan Newmarch, jan@newmarch.name
If you like this book, please contribute using Flattr
or donate using PayPal
Changes
version 1.0
Revised for Go 1
version 0.5
Updated template chapter
Added web sockets chapter
version 0.4
Updated template package to the new template package in the web server chapter
Tested and revised code under release.r60.1 9497
version 0.3
Network Programming with Go
Version 1.0 Page 1©Jan Newmarch - Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Added chapter on new template package
Revised web serer example to use new template package
version 0.2
Compiled code under release.r60.1 9497
version 0.1
Initial version
Network Programming with Go
Version 1.0 Page 2©Jan Newmarch - Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Chapter 1 Architecture
skip table of contents
Show table of contents
This chapter covers the major architectural features of distributed sytems.
1.1 Introduction
You can't build a system without some idea of what you want to build. And you can't build it if you don't know the environment in
which it will work. GUI programs are different to batch processing programs; games programs are different to business programs;
and distributed programs are different to standalone programs. They each have their approaches, their common patterns, the
problems that typically arise and the solutions that are often used.
This chapter covers the highl evel architectural aspects of distributed systems. There are many ways of looking at such systems,
and many of these are dealt with.
1.2 Protocol Layers
Distributed systems are hard. There are multiple computers involved, which have to be connected in some way. Programs have to
be written to run on each computer in the system and they all have to co-operate to get a distributed task done.
The common way to deal with complexity is to break it down into smaller and simpler parts. These parts have their own structure,
but they also have defined means of communicating with other related parts. In distributed systems, the parts are called protocol
layers and they have clearly defined functions. They form a stack, with each layer communicating with the layer above and the
layer below. The communication between layers is defined by protocols.
Network communications requires protocols to cover high-level application communication all the way down to wire communication
and the complexity handled by encapsulation in protocol layers.
ISO OSI Protocol
Although it was never properly implemented, the OSI (Open Systems Interconnect) protocol has been a major influence in ways of
talking about and influencing distributed systems design. It is commonly given in the following figure:
OSI layers
The function of each layer is:
Network layer provides switching and routing technologies
Transport layer provides transparent transfer of data between end systems and is responsible for end-to-end error recovery
and flow control
Session layer establishes, manages and terminates connections between applications.
Presentation layer provides independance from differences in data representation (e.g. encryption)
Application layer supports application and end-user processes
TCP/IP Protocol
While the OSI model was being argued, debated, partly implemented and fought over, the DARPA internet research project was
busy building the TCP/IP protocols. These have been immensely succesful and have led to The Internet (with capitals). This is a
much simpler stack:
Distributed Systems Architecture
Version 1.0 Page 3©Jan Newmarch - Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Some Alternative Protocols
Although it almost seems like it, the TCP/IP protocols are not the only ones in existence and in the long run may not even be the
most successful. There are many protocols occupying significant niches, such as
Firewire
USB
Bluetooth
WiFi
Thre is active work continuing on many other protocols, even quite bizarre ones such as those for the "internet in space."
The focus in this book will be on the TCP/IP, but you should be aware of these other ones.
1.3 Networking
A network is a communications system for connecting end systems called hosts. The mechanisms of connection might be copper
wire, ethernet, fibre optic or wireless, but that won't concern us here. A local area network (LAN) connects computers that are
close together, typically belonging to a home, small organisation or part of a larger organisation.
A Wide Area Network (WAN) connects computers across a larger physical area, such as between cities. There are other types as
well, such as MANs (Metropolitan Area Network), PANs (Personal Are Networks) and even BANs (Body Are Network).
An internet is a connection of two or more distinct networks, typically LANs or WANs. An intranet is an internet with all networks
belonging to a single organisation.
There are significant differences between an internet and an intranet. Typically an intranet will be under a single administrative
control, which will impose a single set of coherent policies. An internet on the other hand will not be under the control of a single
body, and the controls exercised over different parts may not even be compatable.
A trivial example of such differences is that an intranet will often be restricted to computers by a small number of vendors running a
standardised version of a particular operating system. On the other hand, an internet will often have a smorgasborg of different
computers and operating systems.
The techniques of this book will be applicable to internets. They will also be valid for intranets, but there you will also find
specialised, non-portable systems.
And then there is the "mother" of all internets: The Internet. This is just a very, very large internet that connects us to Google, my
computer to your computer and so on.
1.4 Gateways
A gateway is a generic term for an entity used to connect two or more networks. A repeater operates at the physical level copies
the information from one subnet to another. A bridge operates at the data link layer level and copies frames between networks. A
router operates at the network level and not only moves information between networks but also decides on the route.
1.5 Packet encapsulation
The communication between layers in either the OSI or the TCP/IP stacks is done by sending packets of data from one layer to
the next, and then eventually across the network. Each layer has administrative information that it has to keep about its own layer.
It does this by adding header information to the packet it receives from the layer above, as the packet passes down. On the
receiving side, these headers are removed as the packet moves up.
For example, the TFP (Trivial File Transfer Protocol) moves files from one computer to another. It uses the UDP protocol on top of
the IP protocol, which may be sent over Ethernet. This looks like:
Distributed Systems Architecture
Version 1.0 Page 4©Jan Newmarch - Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
The packet transmitted over ethernet, is of course the bottom one.
1.6 Connection Models
In order for two computers to communicate, they must set up a path whereby they can send at least one message in a session.
There are two major models for this:
Connection oriented
Connectionless
Connection oriented
A single connection is established for the session. Two-way communications flow along the connection. When the session is over,
the connection is broken. The analogy is to a phone conversation. An example is TCP
Connectionless
In a connectionless system, messages are sent independant of each other. Ordinary mail is the analogy. Connectionless messages
may arrive out of order. An example is the IP protocol. Connection oriented transports may be established on top of connectionless
ones - TCP over IP. Connectionless transports my be established on top of connection oriented ones - HTTP over TCP.
There can be variations on these. For example, a session might enforce messages arriving, but might not guarantee that they
arrive in the order sent. However, these two are the most common.
1.7 Communications Models
Message passing
Some non-procedural languages are built on the principle of message passing. Concurrent languages often use such a mechanism,
and the most well known example is probably the Unix pipeline. The Unix pipeline is a pipeline of bytes, but there is not an inherent
limitation: Microsoft's PowerShell can send objects along its pipelines, and concurrent languages such as Parlog could send
arbitrary logic data structures in messages between concurrent processes.
Message passing is a primitive mechanism for distributed systems. Set up a connection and pump some data down it. At the other
end, figure out what the message was and respond to it, possibly sending messages back. This is illustrated by
Distributed Systems Architecture
Version 1.0 Page 5©Jan Newmarch - Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
剩余122页未读,继续阅读
zhkeji
- 粉丝: 2
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- RTL8188FU-Linux-v5.7.4.2-36687.20200602.tar(20765).gz
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论3