Skip to main content
Engineering LibreTexts

3.1: Basic Concepts

  • Page ID
    43799
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Socket

    A remote communication involves at least two system processes exchanging some data bytes through a network. Each process accesses the network through at least one socket (see Figure \(\PageIndex{1}\)). A socket can then be defined as a plug on a communication network.

    Socket communication diagram.
    Figure \(\PageIndex{1}\): Inter-Process Remote Communication Through Sockets.

    Sockets are used to establish a bidirectional communication: they allow both sending and receiving data. Such interaction can be done according to communication protocols which are encapsulated by sockets. On the Internet and other networks such as ethernet LANs1, two basic protocols widely used are TCP/IP and UDP/IP.

    TCP/IP vs. UDP/IP

    TCP/IP stands for Transmission Control Protocol / Internet Protocol (TCP for short). TCP use guarantees a reliable communication (no data loss). It requires that applications involved in the communication get connected before actually communicating. Once a connection is established interacting parties can send and receive an arbitrary amount of bytes. This is often referred to as a stream communication. Data reach the destination in the same order of their sending.

    UDP/IP stands for User Datagram Protocol / Internet Protocol (UDP for short). Datagrams are chunks of data whose size cannot exceed 64KB. UDP is an unreliable protocol for two reasons. First, UDP does not guarantee that datagrams will actually reach their destination. The second reason is that the reception order of multiple datagrams from a single sender to the receiver may arrive in an arbitrary order. Nevertheless, UDP is faster than TCP since no connection is required before sending data. A typical use of UDP is “heart-beating” as used in server-based social application, where clients need to notify the server of their status (e.g., Requesting interactions, or being Invisible).

    In the remainder of this chapter we will focus on TCP Sockets. First, we show how to create a client socket, connect it to a server, exchange data and close the connection (Section 4.2). This lifecycle is illustrated using examples showing the use of client sockets to interact with a web server. Next, Section 4.3 presents server sockets. We describe their life-cycle and how to use them to implement a server that can handle concurrent connections. Last, we introduce socket streams in Section 4.4. We give an overview of their benefits by describing their use on both client and server side.


    1. Local Area Networks

    This page titled 3.1: Basic Concepts is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by Alexandre Bergel, Damien Cassou, Stéphane Ducasse, Jannik Laval (Square Bracket Associates) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.