1)socket的组成,server 和 client
2)server部分的程序包括:
- Create a socket with the
socket() system call
- Bind the socket to an address using the
bind() system call. For a server socket on the Internet, an address consists of a port number on the host machine.
- Listen for connections with the
listen() system call
- Accept a connection with the
accept() system call. This call typically blocks until a client connects with the server.
- Send and receive data
client部分的程序包括:
- Create a socket with the
socket() system call
- Connect the socket to the address of the server using the
connect() system call
- Send and receive data. There are a number of ways to do this, but the simplest is to use theread() andwrite() system calls.
address domain: Unix domain----系统的入口(字符串)和端口号(可以选择2000到65535的任何一个数字)
Internet domain----IP地址和端口号
socket type:stream sockets 用 TCP协议,是一种可靠的,基于stream的协议
datagram sockets 用UDP协议,是一种不可靠的,基于message的协议
4)例程,例程是Internet domain基于stream type的协议的c语言的源程序
server.c http://www.linuxhowtos.org/data/6/server.c
client.c http://www.linuxhowtos.org/data/6/client.c
关于例程的逐行解释,请移步源网址~
----------文章转自http://www.linuxhowtos.org/C_C++/socket.htm