Skip to main content
Engineering LibreTexts

3: Sockets

  • Page ID
    43805
  • \( \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}}\)

    written by:

    Noury Bouraqadi (Noury.Bouraqadi@mines-douai.fr)

    Luc Fabresse (Luc.Fabresse@mines-douai.fr)

    Modern software often involve multiple devices that collaborate through a network. The basic approach to set up such collaborations is to use sockets. A typical use is in the World Wide Web. Browsers and servers interact through sockets that carry HTTP requests and responses.

    The concept of socket was first introduced by researchers from University of Berkeley in the 1960s. They defined the first socket API for the C program- ming language in the context of Unix operating systems. Since then, the concept of socket spread out to other operating systems. Its API was ported to almost all programming languages.

    In this chapter, we present the API of sockets in the context of Pharo. We first show through some examples how to use sockets for building both clients and servers. The notion of client and server are inherent in sockets: a server waits for requests emitted by clients. Then, we introduce SocketStream and how to use it. In practice, one is likely to use SocketStream instead of plain sockets. The chapter ends with a description of some unix networking utilities that are useful for experimenting.


    This page titled 3: Sockets 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.