PHPackages                             antibiotics11/net-socket - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. antibiotics11/net-socket

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

antibiotics11/net-socket
========================

Utility classes for PHP socket programming.

04PHP

Since May 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/antibiotics11/net-socket)[ Packagist](https://packagist.org/packages/antibiotics11/net-socket)[ RSS](/packages/antibiotics11-net-socket/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

net-socket
==========

[](#net-socket)

Utility classes for PHP socket programming.

Classes
-------

[](#classes)

- **NetSocket\\InetAddress:** represents an ip address, domain name, and address family.
- **NetSocket\\Endpoint:** represents a network endpoint with InetAddress and port number pairs.
- **NetSocket\\Socket\\Wrapper\\Socket:** wraps PHP Socket object and socket functions.
- **NetSocket\\Socket\\Wrapper\\SocketError:** wraps PHP socket errors.

Usage
-----

[](#usage)

### TCP server

[](#tcp-server)

```
use antibiotics11\NetSocket\{InetAddress, Endpoint};
use antibiotics11\NetSocket\Socket\Wrapper\{Socket, SocketError};

// Define the server endpoint
$serverEndpoint = new Endpoint(
  inetAddress: InetAddress::getByAddress("127.0.0.1"),
  port:        12345
);

try {

  // Create a server socket
  $serverSocket = Socket::create(
    domain: Socket::DOMAIN_INET,
    type:   Socket::TYPE_STREAM,
    level:  Socket::LEVEL_TCP
  );

  // Bind the server socket to the server endpoint
  $serverSocket->bindTo(endpoint: $serverEndpoint);

  // Start listening for incoming connections
  $serverSocket->listen();

  // Accept an incoming connection
  $clientSocket = $serverSocket->accept();

  // Read data from the client
  $receivedData = $clientSocket->read();

  // Get the remote endpoint of the client
  $clientEndpoint = $clientSocket->getRemoteEndpoint();

  printf("Received \"%s\" from %s\r\n", $receivedData, $clientEndpoint);

  // Shut down the client socket
  $clientSocket->shutdown();

  // Close the server socket
  $serverSocket->close();

} catch (SocketError $e) {
  printf("Socket Error: %s\r\n", $e->getSocketErrorMessage());
}
```

### TCP client

[](#tcp-client)

```
use antibiotics11\NetSocket\{InetAddress, Endpoint};
use antibiotics11\NetSocket\Socket\Wrapper\{Socket, SocketError};

// Define the server endpoint to connect to
$serverEndpoint = new Endpoint(
  inetAddress: InetAddress::getByAddress("127.0.0.1"),
  port:        12345
);

try {

  // Create a client socket
  $clientSocket = Socket::create(
    domain: Socket::DOMAIN_INET,
    type:   Socket::TYPE_STREAM,
    level:  Socket::LEVEL_TCP
  );

  // Connect the client socket to the server endpoint
  $clientSocket->connectTo(endpoint: $serverEndpoint);

  // Send data to the server
  $clientSocket->write(data: "Hello, Server!");

  // Close the client socket
  $clientSocket->close();

} catch (SocketError $e) {
  printf("Socket Error: %s\r\n", $e->getSocketErrorMessage());
}
```

Requirements
------------

[](#requirements)

- PHP &gt;= 8.3.0
- [jetbrains/phpstorm-attributes](https://github.com/jetbrains/phpstorm-attributes) &gt;= 1.0

Installation
------------

[](#installation)

```
composer require antibiotics11/net-socket:dev-main
```

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/71744f1798505964b70af43a9ad703a51e99e4069a051731e03378290613f57d?d=identicon)[antibiotics11](/maintainers/antibiotics11)

---

Top Contributors

[![antibiotics11](https://avatars.githubusercontent.com/u/75349747?v=4)](https://github.com/antibiotics11 "antibiotics11 (20 commits)")

### Embed Badge

![Health badge](/badges/antibiotics11-net-socket/health.svg)

```
[![Health](https://phpackages.com/badges/antibiotics11-net-socket/health.svg)](https://phpackages.com/packages/antibiotics11-net-socket)
```

###  Alternatives

[sunel/eav

Eav For Artisan.

1533.6k1](/packages/sunel-eav)[coreproc/laravel-wallet-plus

Easily add a virtual wallet to your Laravel models. Features multiple wallets and a ledger system to help keep track of all transactions in the wallets.

2914.6k](/packages/coreproc-laravel-wallet-plus)[tarsana/functional

functional programming library for PHP

542.1k1](/packages/tarsana-functional)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
