All Projects → amphp → Socket

amphp / Socket

Licence: mit
Non-blocking socket and TLS functionality for PHP based on Amp.

Projects that are alternatives of or similar to Socket

Qtswissarmyknife
QSAK (Qt Swiss Army Knife) is a multi-functional, cross-platform debugging tool based on Qt.
Stars: ✭ 196 (+60.66%)
Mutual labels:  server, tcp, udp, client
Zeus
A high performance, cross-platform Internet Communication Engine. Developed with native socket API. Aim at handling millions of concurrent connections.
Stars: ✭ 30 (-75.41%)
Mutual labels:  server, tcp, socket, client
Jstp
Fast RPC for browser and Node.js based on TCP, WebSocket, and MDSF
Stars: ✭ 132 (+8.2%)
Mutual labels:  server, tcp, socket, client
Zserver4d
ZServer4D 是一套从商业项目剥离而出的云服务器中间件,可以承载百万级的分布式负载服务,并且支持IoT及内网穿透
Stars: ✭ 199 (+63.11%)
Mutual labels:  server, tcp, socket, client
Byte Stream
A non-blocking stream abstraction for PHP based on Amp.
Stars: ✭ 208 (+70.49%)
Mutual labels:  async, non-blocking, io, amphp
Netcat
💻 Netcat client and server modules written in pure Javascript for Node.js.
Stars: ✭ 315 (+158.2%)
Mutual labels:  tcp, socket, udp, client
Networksocket
NetworkSocket是一个以中间件(middleware)扩展通讯协议,以插件(plug)扩展服务器功能的支持SSL安全传输的通讯框架;目前支持http、websocket、fast、flex策略与silverlight策略协议。
Stars: ✭ 435 (+256.56%)
Mutual labels:  server, tcp, socket, client
Oksocket
An blocking socket client for Android applications.
Stars: ✭ 2,359 (+1833.61%)
Mutual labels:  server, tcp, socket, client
Simplenetwork
simple TCP server / client C++ linux socket
Stars: ✭ 225 (+84.43%)
Mutual labels:  server, tcp, socket, client
socket
Dazzle Async Socket
Stars: ✭ 19 (-84.43%)
Mutual labels:  socket, unix, tcp, udp
Laravel S
LaravelS is an out-of-the-box adapter between Swoole and Laravel/Lumen.
Stars: ✭ 3,479 (+2751.64%)
Mutual labels:  async, server, tcp, udp
Yasio
A multi-platform support c++11 library with focus on asio (asynchronous socket I/O) for any client application.
Stars: ✭ 483 (+295.9%)
Mutual labels:  tcp, socket, udp
Sockets
🔌 Non-blocking TCP socket layer, with event-driven server and client.
Stars: ✭ 559 (+358.2%)
Mutual labels:  async, non-blocking, tcp
Elixir Socket
Socket wrapping for Elixir.
Stars: ✭ 642 (+426.23%)
Mutual labels:  tcp, socket, udp
Parallec
Fast Parallel Async HTTP/SSH/TCP/UDP/Ping Client Java Library. Aggregate 100,000 APIs & send anywhere in 20 lines of code. Ping/HTTP Calls 8000 servers in 12 seconds. (Akka) www.parallec.io
Stars: ✭ 777 (+536.89%)
Mutual labels:  async, tcp, udp
Bizsocket
异步socket,对一些业务场景做了支持
Stars: ✭ 469 (+284.43%)
Mutual labels:  tcp, socket, client
Vibora
Fast, asynchronous and elegant Python web framework.
Stars: ✭ 5,734 (+4600%)
Mutual labels:  async, server, client
Beetlex
high performance dotnet core socket tcp communication components, support TLS, HTTP, HTTPS, WebSocket, RPC, Redis protocols, custom protocols and 1M connections problem solution
Stars: ✭ 802 (+557.38%)
Mutual labels:  non-blocking, tcp, socket
Clientserverproject
一个C-S模版,该模版由三部分的程序组成,一个服务端运行的程序,一个客户端运行的程序,还有一个公共的组件,实现了基础的账户管理功能,版本控制,软件升级,公告管理,消息群发,共享文件上传下载,批量文件传送功能。具体的操作方法见演示就行。本项目的一个目标是:提供一个基础的中小型系统的C-S框架,客户端有三种模式,无缝集成访问,winform版本,wpf版本,asp.net mvc版本,方便企业进行中小型系统的二次开发和个人学习。同时网络组件方便的支持读写三菱和西门子PLC的数据,详细见Readme
Stars: ✭ 873 (+615.57%)
Mutual labels:  server, socket, client
Tinytcpserver
A small tcp server working under Mono or .NET (4.0) and provides hooks for handling data exchange with clients (works under mono and .net). Behaviour/protocol/reaction could be specified via custom C# script.
Stars: ✭ 14 (-88.52%)
Mutual labels:  server, tcp, socket

socket

Build Status CoverageStatus License

amphp/socket is a socket library for establishing and encrypting non-blocking sockets PHP based on Amp.

Installation

This package can be installed as a Composer dependency.

composer require amphp/socket

Documentation

Documentation can be found on amphp.org as well as in the ./docs directory.

Examples

You can find more examples in the ./examples directory.

Client Example

<?php // basic (and dumb) HTTP client

require __DIR__ . '/../vendor/autoload.php';

// This is a very simple HTTP client that just prints the response without parsing.
// league/uri-schemes required for this example.

use Amp\ByteStream;
use Amp\Loop;
use Amp\Socket\ClientTlsContext;
use Amp\Socket\ConnectContext;
use Amp\Socket\EncryptableSocket;
use League\Uri;
use function Amp\Socket\connect;

Loop::run(static function () use ($argv) {
    $stdout = ByteStream\getStdout();

    if (\count($argv) !== 2) {
        yield $stdout->write('Usage: examples/simple-http-client.php <url>' . PHP_EOL);
        exit(1);
    }

    $uri = Uri\Http::createFromString($argv[1]);
    $host = $uri->getHost();
    $port = $uri->getPort() ?? ($uri->getScheme() === 'https' ? 443 : 80);
    $path = $uri->getPath() ?: '/';

    $connectContext = (new ConnectContext)
        ->withTlsContext(new ClientTlsContext($host));

    /** @var EncryptableSocket $socket */
    $socket = yield connect($host . ':' . $port, $connectContext);

    if ($uri->getScheme() === 'https') {
        yield $socket->setupTls();
    }

    yield $socket->write("GET {$path} HTTP/1.1\r\nHost: $host\r\nConnection: close\r\n\r\n");

    while (null !== $chunk = yield $socket->read()) {
        yield $stdout->write($chunk);
    }

    // If the promise returned from `read()` resolves to `null`, the socket closed and we're done.
    // In this case you can also use `yield Amp\ByteStream\pipe($socket, $stdout)` instead,
    // but we want to demonstrate the `read()` method here.
});

Server Example

<?php // basic (and dumb) HTTP server

require __DIR__ . '/../vendor/autoload.php';

// This is a very simple HTTP server that just prints a message to each client that connects.
// It doesn't check whether the client sent an HTTP request.

// You might notice that your browser opens several connections instead of just one,
// even when only making one request.

use Amp\Loop;
use Amp\Socket\ResourceSocket;
use Amp\Socket\Server;
use function Amp\asyncCoroutine;

Loop::run(static function () {
    $clientHandler = asyncCoroutine(static function (ResourceSocket $socket) {
        $address = $socket->getRemoteAddress();
        $ip = $address->getHost();
        $port = $address->getPort();

        echo "Accepted connection from {$address}." . PHP_EOL;

        $body = "Hey, your IP is {$ip} and your local port used is {$port}.";
        $bodyLength = \strlen($body);

        $req = "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length: {$bodyLength}\r\n\r\n{$body}";
        yield $socket->end($req);
    });

    $server = Server::listen('127.0.0.1:0');

    echo 'Listening for new connections on ' . $server->getAddress() . ' ...' . PHP_EOL;
    echo 'Open your browser and visit http://' . $server->getAddress() . '/' . PHP_EOL;

    while ($socket = yield $server->accept()) {
        $clientHandler($socket);
    }
});

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

License

The MIT License (MIT). Please see LICENSE for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].