Berkeley Socket API – Creating a TCP/IP Server in C
2011-09-10 18:56
417 查看
Berkeley Socket API – Creating a TCP/IP Server in C
Programming Languages
CAPI
Berkeley Socket APIWhat are sockets?
“In computer networking, an Internet socket (or commonly, a network socket or socket) is the endpoint of a bidirectional inter-process communication flow across an Internet Protocol-based computer network, such as the Internet. Internet sockets (in plural) are an application programming interface (API) application program and the TCP/IP stack, usually provided by the operating system. Internet sockets constitute a mechanism for delivering incoming data packets to the appropriate application process or thread, based on a combination of local and remote IP addresses and port numbers. Each socket is mapped by the operational system to a communicating application process or thread.”in Wikipedia
Data Structure used to store socked details
Data Structure used to store a time value
Used on ‘select’ for timeoutsFilling the socket address
Creating the socket
domain
AF_UNIX – UNIX internal protocolsAF_INET – ARPA Internet protocols
AF_ISO – ISO protocols
AF_NS – Xerox Network Systems protocols
AF_IMPLINK – IMP host at IMP link layer
Type
SOCK_STREAM – provides sequenced, reliable, two-way connection based byte streamsSOCK_DGRAM – connectionless, unreliable messages of a fixed (typically small) maximum length
SOCK_RAW – sockets provide access to internal network protocols and interfaces
SOCK_SEQPACKET – provide a sequenced, reliable, two-way connection-based data transmission path for datagrams of fixed maximum length
SOCK_RDM – Not implemented
Returns
0 – Error1+ – Socket descriptor
Bind the socket
address – Socket address (address, port, family…)
address_len – Structure address size
Listen on socket
backlog – Maximum pending connections on queue
Returns
0 – OK-1 – Error
Wait for socket to be ready
readfds – ‘set’ of descriptors to read from
writefds – ‘set’ of descriptors to write to
errorfds – ‘set’ of descriptors to expect errors from
timeout – time to wait before giveout a timeout
Returns
1+ – Socket descriptor0 – Timeout
-1 – Error
Accepting an incoming connection
address – Socket address (address, port, family…)
address_len – Structure address size
Returns
1+ – Descriptor of the new socket-1 – Error
Read and write from a socket
It works exactly like when we’re reading from a file, pipe, etc.Read from socket
The server code revealed
相关文章推荐
- Berkeley Socket API – Creating a TCP/IP client in C
- Redis 启动报错: Creating Server TCP listening socket *:6379: bind: Address already in use
- 开启redis-server提示 # Creating Server TCP listening socket *:6379: bind: Address already in use--解决方法
- Remote Connection via Proxy Server in TCP/IP Socket
- service structure flowchart [mobile to server via HTTP RESTful API and TCP/IP in a map]
- 开启redis-server报错 # Creating Server TCP listening socket *:6379: bind: Address already in use--解决方法
- redis启动出错Creating Server TCP listening socket 127.0.0.1:6379: bind: No error--转载
- windows redis 连接错误Creating Server TCP listening socket 127.0.0.1:637 9: bind: No error
- Redis Creating Server TCP listening socket *:6379: unable to bind socket
- Java TCPIP 编程 那些事 ServerSocket (一)
- 启动redis出现Creating Server TCP listening socket *:6379: bind: No such file or directory
- 启动redis出现Creating Server TCP listening socket *:6379: bind: No such file or directory
- A Crash Course in UNIX TCP/IP Socket Programming
- [6644] 02 Apr 23:11:58.976 # Creating Server TCP listening socket *:6379: bind: No such file or directory
- socket 编程入门教程(一)TCP server 端:3、sockaddr与sockaddr_in
- TCP/IP socket programming in C(一)
- win10 下 Redis 服务端启动异常 Creating Server TCP listening socket 127.0.0.1:6379: bind: No error
- creating server tcp listening socket 127.0.0.1:6379: bind No error
- Android网络编程之TCP/IP的Socket、ServerSocket模式
- redis启动出错Creating Server TCP listening socket 127.0.0.1:6379: bind: No error