---
name: "Sockets.socketPair"
section: "3kaya"
platform: "linux"
package: "kaya"
version: "0.4.4-6.2"
release: "Debian 8 (Jessie)"
platforms: ["linux"]
url: "https://new.carta.tech/Sockets.socketPair"
---

# Sockets.socketPair(3kaya)

Create a joined pair of sockets

## NAME

Sockets::socketPair - Create a joined pair of sockets

## SYNOPSIS

**Pair\<Socket, Socket\> socketPair(** **)**

## DESCRIPTION

This function creates a pair of sockets that can be used for bi-directional communication. The most common use of this is for setting up communications between a process and its **Posix.fork (3kaya)** ()ed child - each process closes one of the sockets after the fork.

-

   sockets = socketPair();\
    pid = fork();\
    if (pid == 0) {\
    // child process\
      close(sockets.fst);\
      // do something\
    } else {\
      close(sockets.snd);\
      // do something else\
    }

## AUTHORS

Kaya standard library by Edwin Brady, Chris Morris and others (kaya@kayalang.org). For further information see http://kayalang.org/

## LICENSE

The Kaya standard library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (version 2.1 or any later version) as published by the Free Software Foundation.

## RELATED

**Sockets.Socket (3kaya)**

**Sockets.close (3kaya)**

**Posix.fork (3kaya)**
