Network Socket (一)

socket这个概念学过计算机的都知道,但是到底什么是socket呢? 这个抽象的概念在linux操作系统下面是怎么实现的呢?这篇个系列的短文尝试着
  • 什么是套接字?
    • socket is a standard way to perform network communication through the OS;
    • it is a programmer’s abstraction to take care of details of OSI comm;
    • it sends and receives data;
  • 有几种不同的套接字?
    • steam socket – connection-oriented, reliable (on TCP)
    • datagram socket – connectionless, unreliable (on UDP)
  • 有那些基本的套接字应用函数?(Linux)
    • socket (int domain, int type, int prot)
      • create a socket
      • return a file descriptor
      • domain :  spec. protocol family of socket fd
      • type : spec. types of socket, e.g. datagram, stream data
      • prot : almost always be 0. Selects protocol from family
    • connect (int fd, struct sockadd *remothost, scoklen_t addr_length)
      • connect a socket to to a remote host
    • bind (int fd, struct sockaddr *localadd, socklen_t addr_length)
      • binds a socket to local address
    • listen (int fd, int backlog_queue_size)
      • listens for connection and queue requests into backlog
    • accept (int fd, sockadd *remothost, socklen_t *addr_length)
      • accepts an incoming request
    • send (int fd, void *buffer, size_t n, int flags)
      • sends n data from buffer to socket fd
    • recv (int fd, void *buffer, size_t n, int flags)
      • receive n bytes from socket fd into buffer


Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  更改 )

Google+ photo

You are commenting using your Google+ account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )


Connecting to %s

%d 博主赞过: