Personal tools

Types of Sockets

Salem_MA_69332_n
(Salem, Massachusetts - Harvard Taiwan ROC Student Club)

 

 

- Network Sockets

A socket is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent to. An endpoint is a combination of an IP address and a port number. Every TCP connection can be uniquely identified by its two endpoints. That way you can have multiple connections between your host and the server. 

A network socket is an internal endpoint for sending or receiving data within a node on a computer network. Concretely, it is a representation of this endpoint in networking software (protocol stack), such as an entry in a table (listing communication protocol, destination, status, etc.), and is a form of system resource.

A process can refer to a socket using a socket descriptor, a type of handle. A process first requests that the protocol stack create a socket, and the stack returns a descriptor to the process so it can identify the socket. The process then passes the descriptor back to the protocol stack when it wishes to send or receive data using this socket.

In practice, socket usually refers to a socket in an Internet Protocol (IP) network (where a socket may be called an Internet socket), in particular for the Transmission Control Protocol (TCP), which is a protocol for one-to-one connections. In this context, sockets are assumed to be associated with a specific socket address, namely the IP address and a port number for the local node, and there is a corresponding socket address at the foreign node (other node), which itself has an associated socket, used by the foreign process. Associating a socket with a socket address is called binding.

 

- Types of Sockets

There are four types of sockets. The first 2 are more commonly used than the second 2 types :

  • Stream Sockets: Delivery in a networked environment is guaranteed. These use TCP (Transmission Control Protocols) for data transmission. A stream socket is a type of interprocess communication socket or network socket, which provides a connection-oriented, sequenced, and unique flow of data without record boundaries, with well-defined mechanisms for creating and destroying connections and for detecting an error. A stream socket transmits data reliably, in order and with out-of-band capabilities. If you send three items “A, B, C” then the receiver will receive it in the same order. 
  • Datagram Sockets: Delivery in a networked environment is not guaranteed. These UDP (User Datagram Protocols) for data transmission. 
  • Raw Sockets: These provide user access to the underlying communication protocols, which support socket abstractions. They are not intended for general use. 
  • Sequenced Packet Sockets (SPS): Sequenced Packet Sockets similar to Stream Sockets, with the exception that record boundaries are preserved. SPP interface is only provided as part of the network system socket abstraction and is very important in most serious network system applications. It allows the user to modify the SP Protocols header on a packet or a group of packets, either by writing a prototype header along whatever data is to be sent or by specifying a default header to be used with all outgoing data. 
  • SPS allows the user to receive the header on incoming packets.


The process defined above is to communicate between the same types of sockets. But there is no restriction in communicating  between the different types of socket.

 


[More to come ...]

 

Document Actions