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 Sockets: socket method

From Wiki
Jump to: navigation, search
Article Metadata
Article
Created: polaka_sr (17 Jun 2008)
Last edited: hamishwillee (08 Feb 2012)

The socket method creates an endpoint for communication.

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

The socket system call creates an endpoint for communication and returns a descriptor.

The domain argument specifies a communications domain within which communication will take place; this selects the protocol family which should be used. These families are defined in the include file sys/socket.h. The protocol argument specifies a particular protocol to be used with the socket.

Following code snippet shows the usage of socket function:

#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);
}


Wiki Links

Open C Sockets Overview

This page was last modified on 8 February 2012, at 02:52.
52 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.

×