PHPackages                             tourze/workerman-rfc3489 - 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. tourze/workerman-rfc3489

ActiveLibrary

tourze/workerman-rfc3489
========================

Workerman RFC3489协议实现

0.0.2(5mo ago)00MITPHPCI passing

Since Nov 14Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/workerman-rfc3489)[ Packagist](https://packagist.org/packages/tourze/workerman-rfc3489)[ RSS](/packages/tourze-workerman-rfc3489/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (10)Versions (3)Used By (0)

Workerman RFC3489 (STUN Protocol) Implementation
================================================

[](#workerman-rfc3489-stun-protocol-implementation)

[English](README.md) | [中文](README.zh-CN.md)

[![PHP Version](https://camo.githubusercontent.com/ef363a5a30025ffef1857918c40fa01e97f03929e5f87d12a14bf334a7de9220/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d3838393242462e737667)](https://php.net/)[![Latest Version](https://camo.githubusercontent.com/2231f3417d20a2ec87aec2eaade089fa06b715be6528bd5d75b69c51c1773a67/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f776f726b65726d616e2d726663333438392e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/workerman-rfc3489)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![Build Status](https://github.com/tourze/php-monorepo/workflows/CI/badge.svg)](https://github.com/tourze/php-monorepo/actions)[![Code Coverage](https://camo.githubusercontent.com/b3545ae1bcdb4ea486f71f87b43001e82dd21933bc8035d44601706c851265da/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e2e737667)](https://github.com/tourze/php-monorepo)[![Total Downloads](https://camo.githubusercontent.com/f154b238178d973b27308269fbb5ee396d97451d5f31837bab89c0c70b46d26b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f776f726b65726d616e2d726663333438392e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/workerman-rfc3489)

A high-performance implementation of RFC3489 STUN protocol, supporting NAT traversal and public IP address discovery.

Description
-----------

[](#description)

This library provides a complete implementation of the RFC3489 STUN (Session Traversal Utilities for NAT) protocol using the Workerman framework. It enables applications to discover their public IP addresses and determine the type of NAT they are behind, which is essential for peer-to-peer communication and media streaming applications.

Features
--------

[](#features)

- Complete RFC3489 STUN protocol implementation
- Support for Binding requests and Shared Secret requests
- Built-in NAT type detection
- High performance and low latency
- Clean and intuitive API
- Comprehensive test coverage
- Full IPv4 and IPv6 support

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

[](#installation)

```
composer require tourze/workerman-rfc3489
```

Quick Start
-----------

[](#quick-start)

### Creating STUN Messages

[](#creating-stun-messages)

Use the MessageFactory to easily create various types of STUN messages:

```
use Tourze\Workerman\RFC3489\Message\MessageFactory;
use Tourze\Workerman\RFC3489\Message\ErrorCode;

// Create a Binding request
$request = MessageFactory::createBindingRequest();

// Create a Binding response
$response = MessageFactory::createBindingResponse(
    $request->getTransactionId(),
    '192.168.1.100',
    12345
);

// Create an error response
$errorResponse = MessageFactory::createBindingErrorResponse(
    $request->getTransactionId(),
    ErrorCode::SERVER_ERROR,
    'Internal server error'
);
```

### Setting up a STUN Client

[](#setting-up-a-stun-client)

```
use Tourze\Workerman\RFC3489\Protocol\StunClient;

// Create STUN client with server address and port
$client = new StunClient('stun.l.google.com', 19302);

// Discover public IP address
try {
    [$publicIp, $publicPort] = $client->discoverPublicAddress();
    echo "Public IP: {$publicIp}:{$publicPort}";
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
} finally {
    $client->close();
}
```

### Setting up a STUN Server

[](#setting-up-a-stun-server)

```
use Tourze\Workerman\RFC3489\Protocol\Server\StunServerFactory;

// Create STUN server factory
$factory = new StunServerFactory();

// Create server listening on port 3478
$server = $factory->createWorkermanServer('0.0.0.0', 3478);

// Start server
$server->start();
```

### NAT Type Detection

[](#nat-type-detection)

```
use Tourze\Workerman\RFC3489\Protocol\NatTypeDetector;

// Create NAT detector with STUN server details
$detector = new NatTypeDetector('stun.l.google.com', 19302);

// Detect NAT type
$natType = $detector->detect();
echo "NAT Type: " . $natType->value;
echo "Description: " . $natType->getDescription();
echo "Supports P2P: " . ($natType->isSupportP2P() ? 'Yes' : 'No');
```

Usage
-----

[](#usage)

### Basic Configuration

[](#basic-configuration)

```
use Tourze\Workerman\RFC3489\Protocol\StunClient;
use Psr\Log\LoggerInterface;

// Create client with custom timeout and logger
$client = new StunClient(
    'stun.l.google.com',
    19302,
    null,           // transport (null for default UDP)
    $logger,        // PSR-3 logger instance
    5000           // timeout in milliseconds
);
```

### Advanced Usage

[](#advanced-usage)

For more complex scenarios, you can extend the base classes or implement custom handlers:

```
use Tourze\Workerman\RFC3489\Protocol\Server\Handler\StunMessageHandlerInterface;
use Tourze\Workerman\RFC3489\Message\StunMessage;

class CustomBindingHandler implements StunMessageHandlerInterface
{
    public function handleMessage(StunMessage $request, string $clientIp, int $clientPort): ?StunMessage
    {
        // Custom handling logic for STUN requests
        // Return response message or null if no response needed
        return $response;
    }
}
```

Security
--------

[](#security)

This implementation includes several security considerations:

- Transaction ID validation to prevent replay attacks
- Message integrity checks using HMAC-SHA1
- Proper error handling for malformed messages
- Rate limiting support for server implementations

Dependencies
------------

[](#dependencies)

- PHP 8.1 or higher
- ext-filter
- ext-hash
- ext-sockets
- psr/log
- symfony/yaml
- tourze/enum-extra
- workerman/workerman

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

Support
-------

[](#support)

If you encounter any issues or have questions, please [create an issue](https://github.com/tourze/php-monorepo/issues) on GitHub.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance77

Regular maintenance activity

Popularity0

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity26

Early-stage or recently created project

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.

###  Release Activity

Cadence

Every ~1 days

Total

2

Last Release

175d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-workerman-rfc3489/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-workerman-rfc3489/health.svg)](https://phpackages.com/packages/tourze-workerman-rfc3489)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[simplesamlphp/simplesamlphp

A PHP implementation of a SAML 2.0 service provider and identity provider.

1.1k12.4M192](/packages/simplesamlphp-simplesamlphp)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19462.3M1.3k](/packages/drupal-core)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)

PHPackages © 2026

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