Note: UNIX Network Programming

原创 2010年06月02日 13:57:00


int socket (int family, int type, int protocol)


Family:   AF_INET


Type:      SOCK_STREAM



Protocol: 0                             

Return value:-1 is returned if an error occurs; otherwise  the  return  value is 

a   descriptor referencing the socket.

bind()-把一个名字绑定到 socket

int bind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);


sockfd:      socket descriptor from socket() return

my_addr:  local address

addrlen length of my_addr


listen()—在 socket 上监听连接

int listen(int s, int backlog);


s: is the TCP socket (already bound to an address)

backlog:the number of incoming connections the kernel  should be able to keep track of.


accept()--accept a connection on a socket


int accept(int s, struct sockaddr *addr, socklen_t *addrlen);


s: socket descript that is the passive mode TCP socket

addr: is a pointer to allocated space

addrlen: is a value-result argument, must be set to the size of cliaddr, will be set on return to be the number of bytes in cliaddr set by the call to accept

accept()  is called by a TCP server to return the next  completed connection from the completed connection queue which is created by listen system call.  After accept returns a new socket descriptor ,I/O can be done using the read() and write() system calls.

If  no  pending connections are present on the queue, and the socket is not marked as non-blocking, accept blocks the caller until a connection is  present.  If the socket is marked non-blocking and no pending connections are present on the queue, accept returns EAGAIN.

connect()--initiate a connection on a socket

int  connect(int  sockfd,  const  struct sockaddr *serv_addr, socklen_t addrlen);

Unix Network Programming(1)---基本概念说法

一个简单的时间获取函数#include 'unp' //包含自己编写的头文件,该头文件包含大多数网络程序都需要的许多系统头文件, 并定义了所用到的各种常值 i...
  • liyuan_35023
  • liyuan_35023
  • 2015年10月16日 21:06
  • 439

Unix Network Programming 2nd Edtion Source Code 编译问题解决

按照README的指示走 #cd unpv12e #cd lib #make gcc -g -O2 -D_REENTRANT -Wall -c -o connect_nonb.o conn...
  • liangxiaozhang
  • liangxiaozhang
  • 2012年11月16日 17:56
  • 542


以下著作均可在此地址下载: 中文名称:计算机科学经典著作 英文名称:Computer Science 版本:[2日更...
  • longerzone
  • longerzone
  • 2014年06月19日 11:29
  • 1452

Unix Network (1)

开篇: 为了更好的学习! 资料来自  Unix Network Programming 1. TCP 三路握手
  • eagle042
  • eagle042
  • 2014年03月16日 18:42
  • 152

[翻译练习]UNIX Network Programming Volume1, Third Edition 1.1(001)

Chapter 1. Introduction1.1 IntroductionWhen writing programs that communicate across a computer netw...
  • ltolll
  • ltolll
  • 2010年01月01日 09:30
  • 895

Unix Systems Programming

开放课程学习列表 CS360 -- Systems Programming James S. Plank, University of Tennessee http://web.eecs.utk.e...
  • DaI253
  • DaI253
  • 2015年12月08日 14:55
  • 148

Beej Network Programming Note

#include const char *inet_ntop(int af, const void *src,                     char *dst, socklen_t siz...
  • missinglosses
  • missinglosses
  • 2010年11月24日 14:20
  • 183

关于APUE(Advanced Programming in the Unix Environment)第三版 代码在ubuntu中的编译运行

1. 下载代码: 2. 安装依赖库:sudo apt-get install libbsd-dev 3. 进入下载目录m...
  • hellochenlu
  • hellochenlu
  • 2016年01月09日 18:38
  • 826

Network Programming for Microsoft Windows 2nd(Windows 网络编程第二版) 学习心得

Winsock 头文件和所要求链接的库1.winsock2.h Ws2_32.lib  (Winsock 2)2.winsock.h wsock32.lib  (Winsock 1, Windows ...
  • exy337
  • exy337
  • 2010年10月26日 10:02
  • 2287

Advanced Programming in UNIX Environment Episode 3

APUE Episode 3
  • myfather103
  • myfather103
  • 2017年09月10日 20:06
  • 119
您举报文章:Note: UNIX Network Programming