Network Programming
lastmod 2024-05-31created 2014-02-2617 edits
Notes on network programming.
Before developing, you need basic knowledge of the OSI model and the Internet protocol suite.
Category
Game network libraries
These high-level, cross-platform network libraries all look like they’re appropriate for game development:
- Raknet
- Ice
- PocoProject
Here are some other high-level libraries I looked at but don’t think are appropriate:
- Zoidcom – no pricing available on the site, which is a hassle up front.
- Torque Network Library (TNL) – no longer supported.
- TNL2 – also appears dead; GPL license prevents use in commercial game clients.
- ENet – lacking high-level documentation.
- ACE – looks dauntingly complex.
And here are some lower-level or more purpose-specific libraries:
- ZeroMQ – great for server-to-server but I wouldn’t use it for client->server: not robust against hacking.
- Boost ASIO – solid and complete, but (flame) using boost is a religious issue for some because it is especially hard-to-read C++ code, and can dramatically increase build-time (/flame).
- LibEvent – doesn’t support Windows well (only uses select, not IOCP).
- LibEv – doesn’t support Windows
- Google Protocol Buffers
- Apache Thrift
AF vs PF
Explains the differences between AF and PF.
- PF_INET: one of the protocol families.
- AF_INET: one of the address families.
Typical protocol families (Protocol Family) are listed below. These are used when defining the address family in an address structure.
| PF_INET | IPv4 Internet protocol. |
| PF_INET6 | IPv6 Internet protocol. |
| PF_LOCAL | UNIX protocol for LOCAL communication. |
| PF_PACKET | Interface for low level sockets. |
| PF_IPX | IPX Novell protocol. |
Typical address families (Address Family) are listed below.
| AF_INET | IPv4 Internet protocol. |
| AF_INET6 | IPv6 Internet protocol. |
| AF_LOCAL | UNIX protocol for LOCAL communication. |
When creating a socket, you must set the protocol with the environment the socket will be used in in mind. In other words, the protocol family determines, at socket creation, which protocol the socket will use to communicate. Note that sockets are not used only for network communication. On Unix-like systems they are also used for communication between processes within the system. The commonly used PF_INET is one of the protocol families. PF_INET, which denotes a protocol family, and AF_INET, which denotes an address family, have the same constant value. Even so, it is not good practice to use PF_INET where address information is set and AF_INET where protocol family information is set.
In conclusion,
- where you set the protocol family, use constants starting with PF,
- and where you set the address family, it is best to use constants starting with AF.
In actual code, you may pass AF_INET as the protocol family to socket(), but passing PF_INET is preferable; likewise, when putting the address family into a sockaddr_in structure you may use PF_INET, but AF_INET is preferable.
See also
- Socket
- Maximum transmission unit (MTU)
- Maximum segment size (MSS)
- Time to live (TTL)
- Computer Network
- Windows Sockets API (Winsock/WinSock/WinSock2/WSA)
- OSI model
- Internet protocol suite
- Network monitoring
Favorite site
- Wikipedia (en) description of network programming
- Hello world: Understanding the TCP/IP network stack 1
- Stackoverflow: Best C/C++ Network Library
- [Recommended] BeeJ's Guide to Network Programming
- Raw IP Networking FAQ (answers to questions about low-level IP networking)
- Winsock Programmer's FAQ 2