DEV Community

Noah11012
Noah11012

Posted on • Updated on

Socket Programming in C: Communication Styles

Being there are multiple different types of sockets available for our use, we will take a brief look at some of them. When we get to socket creation, the second argument takes a number that represents the communication style. Each number has a symbolic constant.

1. SOCK_STREAM

A socket that streams data over a connection like a cable or a pipe. It transmits data like a stream of bytes reliably.

2. SOCK_DGRAM

This style of sockets doesn't have a connection but instead, each packet is addressed and sent individually. Also, this an unreliable style of communication unlike SOCK_STREAM. Each data written to this kind of socket is converted into one packet. The only guarantee this socket gives you is it will try its best to transmit every packet you send.

3. SOCK_RAW

Most user-level programs will not use this kind of communication as it provides low-level access to protocols and interfaces.

Top comments (0)