linux网络编程之socket函数
来源:互联网 发布:java点餐系统源代码 编辑:程序博客网 时间:2024/05/21 07:54
socket()--Create Socket
Syntax
#include <sys/types.h>
#include <sys/socket.h>
int socket(int address_family,
int type,
int protocol)
The socket() function is used to create an end point forcommunications. The end point is represented by the socket descriptor returnedby the socket() function.
Parameters
address_family
(Input) The address family to be used with the socket. Supported value sare:
AF_INET For interprocess communications between processeson the same system or different systems in the Internet domain using theInternet Protocol (IPv4).
AF_INET6 For interprocess communications between processeson the same system or different systems in the Internet domain using theInternet Protocol (IPv6 or IPv4).
type
(Input) The type of communications desired. Supported values are:
SOCK_DGRAM Indicates a datagram socket is desired.
SOCK_STREAM Indicates a full-duplex stream socket is desired.
protocol
(Input) The protocol to be used on the socket. Supported values are:
0 Indicates that the default protocol for the type selected is to be used. For example, IPPROTO_TCP is chosen for the protocol if the type was set to SOCK_STREAM and the address family is AF_INET.
Return Value
socket() returns an integer. Possible values are:
-1 (unsuccessful)
n (successful), where n is a socket descriptor.
Usage Notes
The socket address families and types supported by sockets are defined in <sys/socket.h>. The protocols are defined in <netinet/in.h> (Internet protocols).
NAME
socket - create an endpoint for communication
SYNOPSIS
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
int socket(int domain, int type, int protocol);
DESCRIPTION
socket() creates an endpoint for communication and returns a
descriptor.
The domain argument specifies a communication domain; this selects
the protocol family which will be used for communication. These
families are defined in <sys/socket.h>. The currently understood
formats include:
Name Purpose
AF_UNIX, AF_LOCAL Local communication
AF_INET IPv4 Internet protocols
AF_INET6 IPv6 Internet protocols
The socket has the indicated type, which specifies the communication
semantics. Currently defined types are:
SOCK_STREAM Provides sequenced, reliable, two-way, connection-
based byte streams. An out-of-band data transmission
mechanism may be supported.
SOCK_DGRAM Supports datagrams (connectionless, unreliable
messages of a fixed maximum length).
SOCK_RAW Provides raw network protocol access.
RETURN VALUE
On success, a file descriptor for the new socket is returned. On
error, -1 is returned, and errno is set appropriately.
- linux网络编程之socket函数
- Linux网络编程之socket函数
- linux网络编程之C/S流程socket函数
- Linux网络编程之[Socket通信的常用函数简介]
- linux网络编程之Socket
- linux socket网络编程之socket属性
- linux C 编程 之 socket 网络编程
- Linux网络编程之Socket编程
- linux网络编程之Socket编程原理
- linux socket编程之socket()函数介绍
- linux socket编程之socket()函数介绍
- linux socket编程之socket()函数介绍
- Linux网络编程socket bind() 函数
- Linux socket 网络编程常用函数总结
- linux网络编程入门socket函数介绍
- linux网络编程之socket(一):socket概述和字节序、地址转换函数
- linux网络编程之socket(一):socket概述和字节序、地址转换函数
- linux网络编程之socket(一):socket概述和字节序、地址转换函数
- android superuser.apk 管理root权限原理分析
- ubuntu安装后的提示信息
- 谈谈网络变压器
- 未使用分区表造成系统缓慢
- 【每日最爱一句】2013.06.15
- linux网络编程之socket函数
- dede 按权重排序
- some points
- 基于select、poll、epoll的区别详解
- 判断四个扑克是否能算出24点
- PCM帧结构相关整理
- 北漂的大三IT男(二)
- 选择排序(Python版)
- AJAX+PHP的POST中文乱码问题及JS的空格替换