Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Open C 套接字: socket 方法

From Wiki
Jump to: navigation, search
Article Metadata

文章
dougcn 在 24 Jun 2008 创建
最后由 hamishwillee 在 15 Dec 2011 编辑

Open C 套接字: socket 方法

socket方法创建通讯端点。

int socket (int domain, int type, int protocol);

socket系统调用创建通讯端点并返回一个描述符(descriptor)

domain参数指定通讯将发生的通讯领域; 选择应该使用的协议族。协议族定义在包括文件sys/socket.h中。 protocol参数指定套接字使用的特定协议。

下面的代码片段演示了socket函数的用法:

#include <sys/socket.h>
#include <unistd.h>
#include <stdio.h>
#inlcude <netinet/in.h>
void SocketExample()
{
int sock_fd;
sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
close(sock_fd);
}

内部链接

Internal Links

This page was last modified on 15 December 2011, at 05:41.
435 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×