Java TCP/IP Socket Programming (2nd Edition) cover

Java TCP/IP Socket Programming (2nd Edition)

Rating 4.0
Chapters
40
Series
HZ Books Programmer's Library
ISBN
9787111257561

Tags

Summary

This book is the Chinese translation of the second edition of TCP/IP Sockets in Java: Practical Guide for Programmers, aimed at Java developers who need to write network communication programs hands-on. Guided by the principle of "concise theory, code speaks," the book is organized around how TCP/IP sockets are implemented in Java: it first introduces basic concepts such as networks, packets, protocols, addresses and names, and the client/server model, then explains the nature of sockets; it then demonstrates how to write TCP clients, TCP servers, and UDP datagrams, along with how to organize input/output streams. At the data level, the book discusses the encoding of integers, strings, and booleans, framing and parsing, and the construction and parsing of text-based and binary protocol messages, helping readers write messages that different systems can correctly interpret. Advanced sections cover multithreaded servers, one thread per client, thread pools and the Executor framework, blocking and timeout control, broadcast and multicast, Keep-Alive, buffer size, address reuse, lingering after close, and other socket options, as well as connection closing and lifecycle issues. Chapter 5 is devoted to NIO's Channel, Buffer, and Selector, while Chapter 6 analyzes underlying mechanisms in depth from the perspectives of buffering, deadlock risk, and performance. The book is compact, with downloadable sample source code and exercises at the end of each chapter; it is suitable as supplementary reading for university network programming courses and for engineers who want to get up to speed quickly on real projects.

Editor's review

这是一本“薄而硬”的实战小书:172页里塞下了从第一行Socket代码到NIO、多线程服务器、多播与套接字调优的完整路线,几乎没有废话。作者Calvert与Donahoo长期讲授计算机网络课程,写法是典型的“先给最小可运行示例,再解释背后的协议行为”,读者照抄几段代码就能跑通一个能收发消息的客户端与服务器,成就感很强。 相比大量动辄六七百页的Java网络编程教材,本书的取舍非常克制:不追求API大全,而是聚焦实际工程中最常踩的坑——消息怎么编码才不串包、成帧与解析怎么做、阻塞调用怎么设超时、一客户一线程何时该换成线程池、连接关闭之后TIME_WAIT为什么还在占端口。第6章从缓冲、死锁风险与性能角度回看TCP,是全书最有含金量的部分,能帮读者理解“为什么代码这样写会卡住”。 需要注意的是,本书第2版对应Java 1.5–1.7时代,配套源码也以那个时期的API为主,未覆盖后来的异步NIO(NIO.2)与虚拟线程等内容。因此它更适合作为一本打底子的书:把阻塞I/O、多线程与Selector这三条主线吃透,再去看更新的框架与资料。译者序与每章练习也让它很方便作为课程配套或自学清单使用。

Who it's for

A good fit for

  • 已掌握Java基础语法、想系统学网络通信的在读学生
  • 需要自己实现客户端/服务器通信的初中级Java开发者
  • 准备面试中TCP/UDP、I/O模型、多线程服务器等考点的求职者
  • 讲授Java网络编程课程、需要短篇幅教材与练习题的高校教师

Not a good fit for

  • 完全没写过Java、也不了解进程/线程概念的零基础读者
  • 只想直接使用Netty等框架、不打算弄懂底层Socket机制的人
  • 期待覆盖NIO.2、虚拟线程等新版本特性的读者

Reading tips

  1. 手边开一个IDE,把第2章的TCP/UDP示例亲手敲通,再对照抓包工具观察报文流向。
  2. 读第3章时重点自己设计一套协议消息格式,体会成帧与解析为何比“直接write字符串”更可靠。
  3. 第4、5章的多线程与Selector示例建议做压力测试,观察超时、连接数与线程数之间的关系。
  4. 把每章末尾的练习题当作检查清单,做完再进入下一章,避免只读不写。

About the publisher

China Machine Press China · Founded in 1950

In addition to science and technology and professional publishing, the books in our catalog from China Machine Press also reflect a sustained focus on psychology, computing, management, finance and economics, and social sciences. In psychology, the catalog includes works by C. G. Jung and introductions to analytical psychology, as well as applied topics such as stress and health, and addiction and healing. In computing, it features Structure and Interpretation of Computer Programs (JavaScript Edition). Management and finance titles include Administrative Behavior (4th Edition), The Price of Inequality (Collector's Edition), and This Time Is Different: Eight Centuries of Financial Folly (Commemorative Edition). In the philosophy and history of science, there is The Worldview: The Third Edition. Relevant authors include C. G. Jung, William McGuire, Sonu Shamdasani, and Gabor Maté. Public information is limited; the above summarizes the publisher's profile based solely on the books in our catalog.

Contents

  1. Translator's Preface
  2. Preface
  3. Chapter 1 Introduction
  4. 1.1 Computer Networks, Packets, and Protocols
  5. 1.2 About Addresses
  6. 1.3 About Names
  7. 1.4 Clients and Servers
  8. 1.5 What Is a Socket?
  9. 1.6 Exercises
  10. Chapter 2 Basic Sockets
  11. 2.1 Socket Addresses
  12. 2.2 TCP Sockets
  13. 2.2.1 TCP Clients
  14. 2.2.2 TCP Servers
  15. 2.2.3 Input and Output Streams
  16. 2.3 UDP Sockets
  17. 2.3.1 The DatagramPacket Class
  18. 2.3.2 UDP Clients
  19. 2.3.3 UDP Servers
  20. 2.3.4 Sending and Receiving with UDP Sockets
  21. 2.4 Exercises
  22. Chapter 3 Sending and Receiving Data
  23. 3.1 Information Encoding
  24. 3.1.1 Basic Integers
  25. 3.1.2 Strings and Text
  26. 3.1.3 Bit Manipulation: Encoding Booleans
  27. 3.2 Combining Input and Output Streams
  28. 3.3 Framing and Parsing
  29. 3.4 Java-Specific Encodings
  30. 3.5 Building and Parsing Protocol Messages
  31. 3.5.1 Text-Based Representation
  32. 3.5.2 Binary Representation
  33. 3.5.3 Sending and Receiving
  34. 3.6 Closing
  35. 3.7 Exercises
  36. Chapter 4 Advanced Topics
  37. 4.1 Multitasking
  38. 4.1.1 Java Multithreading
  39. 4.1.2 Server Protocols
  40. 4.1.3 Thread per Client

FAQ

这本书和《TCP/IP Sockets in Java》是同一本吗?
是。本书即该书第2版(Practical Guide for Programmers, Second Edition)的中文翻译版,由周恒民翻译、机械工业出版社2009年出版,ISBN为9787111257561。
书里的代码对应哪个Java版本?
主要面向Java 1.5至1.7,涵盖NetworkInterface、InetSocketAddress、Executor等当时新增的抽象,示例在较新的JDK上大多仍可运行,但需注意少量API与废弃类的差异。
没有网络基础能直接读吗?
可以,第1章从分组报文、协议、地址与名字讲起,为后续套接字内容做了铺垫;但完全不懂线程和I/O流的读者,建议先补一点Java基础。
这本书讲NIO讲得深吗?
第5章完整覆盖Channel、Buffer、Selector与数据报信道,并配有练习,足够理解NIO的基本模型;但未涉及NIO.2的文件与异步通道,需要另找资料。
为什么这本书只有一百多页?
它是“实践指南”定位的精简教材,删去了大量API罗列,把篇幅集中在最常用的套接字用法与常见陷阱上,因此更适合快速上手而非当作手册查询。

Comments

Find this book

This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.

Top rated in the same category