You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
25
vendor/swoole/examples/ssl/async_client.php
vendored
Executable file
25
vendor/swoole/examples/ssl/async_client.php
vendored
Executable file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
$client = new swoole_client(SWOOLE_SOCK_TCP | SWOOLE_SSL, SWOOLE_SOCK_ASYNC); //异步非阻塞
|
||||
$client->on("connect", function (swoole_client $cli)
|
||||
{
|
||||
$cli->send("Hello World\n");
|
||||
});
|
||||
|
||||
$client->on("receive", function (swoole_client $cli, $data)
|
||||
{
|
||||
echo "Receive: $data";
|
||||
$cli->close();
|
||||
});
|
||||
|
||||
$client->on("error", function (swoole_client $cli)
|
||||
{
|
||||
echo "error\n";
|
||||
});
|
||||
|
||||
$client->on("close", function (swoole_client $cli)
|
||||
{
|
||||
echo "Connection close\n";
|
||||
});
|
||||
|
||||
$client->connect('127.0.0.1', 9501);
|
||||
echo "connect to 127.0.0.1:9501\n";
|
128
vendor/swoole/examples/ssl/client.c
vendored
Executable file
128
vendor/swoole/examples/ssl/client.c
vendored
Executable file
@ -0,0 +1,128 @@
|
||||
/**
|
||||
* gcc -g -o client client.c -lssl -lcrypt -lcrypto
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <resolv.h>
|
||||
#include <netdb.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#define FAIL -1
|
||||
|
||||
int OpenConnection(const char *hostname, int port)
|
||||
{
|
||||
int sd;
|
||||
struct hostent *host;
|
||||
struct sockaddr_in addr;
|
||||
if ((host = gethostbyname(hostname)) == NULL)
|
||||
{
|
||||
printf("Eroor: %s\n", hostname);
|
||||
perror(hostname);
|
||||
abort();
|
||||
}
|
||||
|
||||
sd = socket(PF_INET, SOCK_STREAM, 0);
|
||||
bzero(&addr, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
addr.sin_addr.s_addr = *(long*) (host->h_addr);
|
||||
|
||||
if (connect(sd, (struct sockaddr*) &addr, sizeof(addr)) != 0)
|
||||
{
|
||||
close(sd);
|
||||
perror(hostname);
|
||||
abort();
|
||||
}
|
||||
return sd;
|
||||
}
|
||||
|
||||
SSL_CTX* InitCTX(void)
|
||||
{
|
||||
SSL_METHOD *method;
|
||||
SSL_CTX *ctx;
|
||||
OpenSSL_add_all_algorithms(); /* Load cryptos, et.al. */
|
||||
SSL_load_error_strings(); /* Bring in and register error messages */
|
||||
|
||||
// method = SSLv3_client_method(); /* Create new client-method instance */
|
||||
method = TLSv1_2_client_method();
|
||||
|
||||
ctx = SSL_CTX_new(method); /* Create new context */
|
||||
if (ctx == NULL)
|
||||
{
|
||||
ERR_print_errors_fp(stderr);
|
||||
printf("Eroor: %s\n", stderr);
|
||||
abort();
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void ShowCerts(SSL* ssl)
|
||||
{
|
||||
X509 *cert;
|
||||
char *line;
|
||||
|
||||
cert = SSL_get_peer_certificate(ssl); /* Get certificates (if available) */
|
||||
if (cert != NULL)
|
||||
{
|
||||
printf("Server certificates:\n");
|
||||
line = X509_NAME_oneline(X509_get_subject_name(cert), 0, 0);
|
||||
printf("Subject: %s\n", line);
|
||||
free(line);
|
||||
line = X509_NAME_oneline(X509_get_issuer_name(cert), 0, 0);
|
||||
printf("Issuer: %s\n", line);
|
||||
free(line);
|
||||
X509_free(cert);
|
||||
}
|
||||
else
|
||||
printf("No certificates.\n");
|
||||
}
|
||||
|
||||
int main(int count, char *strings[])
|
||||
{
|
||||
SSL_CTX *ctx;
|
||||
int server;
|
||||
SSL *ssl;
|
||||
char buf[1024];
|
||||
int bytes;
|
||||
char *hostname, *portnum;
|
||||
if (count != 3)
|
||||
{
|
||||
printf("usage: %s <hostname> <portnum>\n", strings[0]);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
SSL_library_init();
|
||||
hostname = strings[1];
|
||||
portnum = strings[2];
|
||||
ctx = InitCTX();
|
||||
server = OpenConnection(hostname, atoi(portnum));
|
||||
|
||||
ssl = SSL_new(ctx); /* create new SSL connection state */
|
||||
SSL_set_fd(ssl, server); /* attach the socket descriptor */
|
||||
TLSv1_2_client_method();
|
||||
if (SSL_connect(ssl) == FAIL) /* perform the connection */
|
||||
{
|
||||
printf("Eroor: %s\n", stderr);
|
||||
ERR_print_errors_fp(stderr);
|
||||
}
|
||||
else
|
||||
{
|
||||
char *msg = "HelloWorld";
|
||||
printf("Connected with %s encryption\n", SSL_get_cipher(ssl));
|
||||
ShowCerts(ssl); /* get any certs */
|
||||
SSL_write(ssl, msg, strlen(msg)); /* encrypt & send message */
|
||||
bytes = SSL_read(ssl, buf, sizeof(buf)); /* get reply & decrypt */
|
||||
buf[bytes] = 0;
|
||||
printf("Received: \"%s\"\n", buf);
|
||||
SSL_free(ssl); /* release connection state */
|
||||
}
|
||||
close(server); /* close socket */
|
||||
SSL_CTX_free(ctx); /* release context */
|
||||
return 0;
|
||||
}
|
15
vendor/swoole/examples/ssl/client.php
vendored
Executable file
15
vendor/swoole/examples/ssl/client.php
vendored
Executable file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
$client = new swoole_client(SWOOLE_SOCK_TCP | SWOOLE_SSL);
|
||||
if (!$client->connect('192.168.0.44', 9501, -1))
|
||||
{
|
||||
exit("connect failed. Error: {$client->errCode}\n");
|
||||
}
|
||||
echo "connect ok\n";
|
||||
sleep(1);
|
||||
|
||||
for ($i = 0; $i < 1000; $i++)
|
||||
{
|
||||
$client->send("hello world-" . str_repeat('A', $i) . "\n");
|
||||
echo $client->recv();
|
||||
}
|
||||
sleep(1);
|
13
vendor/swoole/examples/ssl/http_client.php
vendored
Executable file
13
vendor/swoole/examples/ssl/http_client.php
vendored
Executable file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
$cli = new Swoole\Http\Client('127.0.0.1', 9501, false);
|
||||
$cli->setHeaders(array('User-Agent' => 'swoole-http-client'));
|
||||
|
||||
$cli->on('close', function($_cli) {
|
||||
echo "connection is closed\n";
|
||||
});
|
||||
$cli->get('/?dump.php?corpid=ding880f44069a80bca1&corpsecret=YB1cT8FNeN7VCm3eThwDAncsmSl4Ajl_1DmckaOFmOZhTFzexLbIzq5ueH3YcHrx', function ($cli) {
|
||||
var_dump($cli);
|
||||
var_dump($cli->headers);
|
||||
echo $cli->body;
|
||||
//$cli->close();
|
||||
});
|
20
vendor/swoole/examples/ssl/passphrase.php
vendored
Executable file
20
vendor/swoole/examples/ssl/passphrase.php
vendored
Executable file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
$client = new swoole_client(SWOOLE_SOCK_TCP | SWOOLE_SSL);
|
||||
$client->set(array(
|
||||
"ssl_key_file" => __DIR__ . '/ssl.key',
|
||||
"ssl_cert_file" => __DIR__ . '/ssl.crt',
|
||||
'ssl_passphrase' => '5524001',
|
||||
));
|
||||
if (!$client->connect('127.0.0.1', 9501, -1))
|
||||
{
|
||||
exit("connect failed. Error: {$client->errCode}\n");
|
||||
}
|
||||
echo "connect ok\n";
|
||||
sleep(1);
|
||||
|
||||
for ($i = 0; $i < 1000; $i++)
|
||||
{
|
||||
$client->send("hello world-" . str_repeat('A', $i) . "\n");
|
||||
echo $client->recv();
|
||||
}
|
||||
sleep(1);
|
35
vendor/swoole/examples/ssl/server.php
vendored
Executable file
35
vendor/swoole/examples/ssl/server.php
vendored
Executable file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
//$serv = new swoole_server("0.0.0.0", 9501, SWOOLE_BASE, SWOOLE_SOCK_TCP | SWOOLE_SSL);
|
||||
$serv = new swoole_server("0.0.0.0", 9501, SWOOLE_PROCESS, SWOOLE_SOCK_TCP | SWOOLE_SSL);
|
||||
$key_dir = dirname(dirname(__DIR__)).'/tests/ssl';
|
||||
|
||||
$port2 = $serv->addlistener('0.0.0.0', 9502, SWOOLE_SOCK_TCP);
|
||||
$port2->on('receive', function($serv, $fd, $from_id, $data){
|
||||
echo "port2: ".$data."\n";
|
||||
});
|
||||
|
||||
$serv->set(array(
|
||||
// 'worker_num' => 4,
|
||||
'ssl_cert_file' => __DIR__.'/corpssl.crt',
|
||||
'ssl_key_file' => __DIR__.'/corpssl.key',
|
||||
'ssl_client_cert_file' => __DIR__.'/ca.crt',
|
||||
'ssl_verify_depth' => 10,
|
||||
));
|
||||
|
||||
$serv->on('connect', function (swoole_server $serv, $fd, $from_id){
|
||||
echo "[#".posix_getpid()."]\tClient@[$fd:$from_id]: Connect.\n";
|
||||
$info = $serv->getClientInfo($fd);
|
||||
var_dump($info);
|
||||
});
|
||||
|
||||
$serv->on('receive', function (swoole_server $serv, $fd, $from_id, $data) {
|
||||
echo "[#".posix_getpid()."]\tClient[$fd]: $data\n";
|
||||
$serv->send($fd, "Swoole: $data\n");
|
||||
});
|
||||
|
||||
$serv->on('close', function ($serv, $fd, $from_id) {
|
||||
echo "[#".posix_getpid()."]\tClient@[$fd:$from_id]: Close.\n";
|
||||
});
|
||||
|
||||
$serv->start();
|
||||
|
13
vendor/swoole/examples/ssl/ssl.crt
vendored
Executable file
13
vendor/swoole/examples/ssl/ssl.crt
vendored
Executable file
@ -0,0 +1,13 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICAzCCAWwCCQCgnsxsw2bDrDANBgkqhkiG9w0BAQsFADBFMQswCQYDVQQGEwJB
|
||||
VTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0
|
||||
cyBQdHkgTHRkMCAXDTE0MDcwOTE0MTIxNloYDzIxMTQwNjE1MTQxMjE2WjBFMQsw
|
||||
CQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJu
|
||||
ZXQgV2lkZ2l0cyBQdHkgTHRkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDP
|
||||
nYsgGr6Q9jqL97xGo2zxrOWGQd96PnItf5uOdvZJjwTLsN8an33UOtFVxwGIaTb8
|
||||
MtuXiLZbslKWLIOoqq0Lk92RwF4Zxs02Yt+S1sM/9ST7tiJQKYx1+rfaZIj0Dy9y
|
||||
VoWHGfRmVZMcWkhslaHR/Yz+Ul4CIqr03/BjYjjQfQIDAQABMA0GCSqGSIb3DQEB
|
||||
CwUAA4GBAJIjeaUeizJ88G1M9fFUTwf11ywWsrzIQxCaMqmzRyrlIhwuC5qXKsA/
|
||||
wHRfj9+KnfJ1LOAguXa/CSRFCogQnYur4+Kzy/PBchMFjIKS9UzmQQWZYsmzBgTX
|
||||
e6pGJN2fxTmpGKf0lj7//NWxOmFDFWgyUeIR4TaAJ5dWpS8Cr0Gc
|
||||
-----END CERTIFICATE-----
|
15
vendor/swoole/examples/ssl/ssl.key
vendored
Executable file
15
vendor/swoole/examples/ssl/ssl.key
vendored
Executable file
@ -0,0 +1,15 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIICXgIBAAKBgQDPnYsgGr6Q9jqL97xGo2zxrOWGQd96PnItf5uOdvZJjwTLsN8a
|
||||
n33UOtFVxwGIaTb8MtuXiLZbslKWLIOoqq0Lk92RwF4Zxs02Yt+S1sM/9ST7tiJQ
|
||||
KYx1+rfaZIj0Dy9yVoWHGfRmVZMcWkhslaHR/Yz+Ul4CIqr03/BjYjjQfQIDAQAB
|
||||
AoGBAL4DtYp7j8BC61ChOvr3pcUG9cbL0UojjwJfUTKxZDXspHn8diT6pgIwltjH
|
||||
23pKuZ1Wuq3U3PnNmlKBiTo8g0R4OudAWJi1kIyY9AXVm9Ffr1wS0krRrOXXJws/
|
||||
P0Y+NtSdpMDEbCiW/GbADPhlWl2JdpOgxdB5mNmCykt4dvRtAkEA7JnxiJWIQg/z
|
||||
Wpy485hrIFwNNNiRJGKVSySZf9itZd+4fC1F6vTlX+ylDemTbYB427dlJ09nINRz
|
||||
gXMW3xh8hwJBAOCjNdhTXCESSeJyt8U5cN0PzIJuKq1CvJdLgaNN+RIsC8v9ZTJF
|
||||
nmMOgjSYNWILRSrHlx0g7VKb2GH6LPsqr9sCQQDKuwGdsdsGGBrB6oYDm/c2zAk4
|
||||
3dRH4/zeXSb1x9iT8QVnyXceYubjsaaf7CM58ZodUeBntX69P60VH2Nal+WjAkEA
|
||||
2r7TziXOjv3KKNLhFRLMTtf1pAU3VaSpFQMX6DgjlIiDrE7CXmPgykD0ldaqFSE4
|
||||
Z2IYSusnbswHt9DwQFzfBQJANhJBIvQgj/BcAV+0qV1NgzXbmywtQcwGg+NcimsH
|
||||
R/tW2SeAXinNkVMjDh5NLzHO5Lz//E0N3lPRljnLfRX69g==
|
||||
-----END RSA PRIVATE KEY-----
|
15
vendor/swoole/examples/ssl/ssl_passwd/ssl.crt
vendored
Executable file
15
vendor/swoole/examples/ssl/ssl_passwd/ssl.crt
vendored
Executable file
@ -0,0 +1,15 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICazCCAdQCCQDGckgNrF7jzDANBgkqhkiG9w0BAQsFADB6MQswCQYDVQQGEwJD
|
||||
TjERMA8GA1UECAwIU2hhbmdIYWkxEDAOBgNVBAcMB01pbmhhbmcxDzANBgNVBAoM
|
||||
BmNoZWx1bjEUMBIGA1UEAwwLaGFudGlhbmZlbmcxHzAdBgkqhkiG9w0BCQEWEHJh
|
||||
bmdvQHN3b29sZS5jb20wHhcNMTcwNjIxMDg0NDIzWhcNMTgwNjIxMDg0NDIzWjB6
|
||||
MQswCQYDVQQGEwJDTjERMA8GA1UECAwIU2hhbmdIYWkxEDAOBgNVBAcMB01pbmhh
|
||||
bmcxDzANBgNVBAoMBmNoZWx1bjEUMBIGA1UEAwwLaGFudGlhbmZlbmcxHzAdBgkq
|
||||
hkiG9w0BCQEWEHJhbmdvQHN3b29sZS5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0A
|
||||
MIGJAoGBAM6DB6/k7gBq335W+46qJKOF2AJ8pJcyr8rwIculc2Guc/8Y7iAnv2gP
|
||||
NuZQWGtXuWNTgEkBc2vP2G2UbsHJRwR8fVgwFphZWmWJ1vomj9RZjm+v1ID04lIw
|
||||
2d2oR4P2Nur7mw6Lxhpgx0y0DJ+4kW4/L/ObV13fJu7fNBKuprtzAgMBAAEwDQYJ
|
||||
KoZIhvcNAQELBQADgYEAPwHwRDG+PCToqybr9GZtz3oxM6ApvVGV0c24Clon8veY
|
||||
57h78tJLVmjx/b6Y4alg4HnT+DDBRZT0hJnBhdtkZivGX7eOys9sUDLZxAWsqO7a
|
||||
bHzHkP0jVawHwqQv7WFoE83pvmUYzj2QbLMULj5PJ4LMlY3bMHYE07c0SVKeJFE=
|
||||
-----END CERTIFICATE-----
|
12
vendor/swoole/examples/ssl/ssl_passwd/ssl.csr
vendored
Executable file
12
vendor/swoole/examples/ssl/ssl_passwd/ssl.csr
vendored
Executable file
@ -0,0 +1,12 @@
|
||||
-----BEGIN CERTIFICATE REQUEST-----
|
||||
MIIBujCCASMCAQAwejELMAkGA1UEBhMCQ04xETAPBgNVBAgMCFNoYW5nSGFpMRAw
|
||||
DgYDVQQHDAdNaW5oYW5nMQ8wDQYDVQQKDAZjaGVsdW4xFDASBgNVBAMMC2hhbnRp
|
||||
YW5mZW5nMR8wHQYJKoZIhvcNAQkBFhByYW5nb0Bzd29vbGUuY29tMIGfMA0GCSqG
|
||||
SIb3DQEBAQUAA4GNADCBiQKBgQDOgwev5O4Aat9+VvuOqiSjhdgCfKSXMq/K8CHL
|
||||
pXNhrnP/GO4gJ79oDzbmUFhrV7ljU4BJAXNrz9htlG7ByUcEfH1YMBaYWVplidb6
|
||||
Jo/UWY5vr9SA9OJSMNndqEeD9jbq+5sOi8YaYMdMtAyfuJFuPy/zm1dd3ybu3zQS
|
||||
rqa7cwIDAQABoAAwDQYJKoZIhvcNAQELBQADgYEASQqPl/+WGbjiFmejmI7cj5Te
|
||||
byHjUASEGc2VDRQhc1W7XRFjHFqyeKRh8xwFV7HDFbvVwsTos260s4PKGkjTD5hH
|
||||
XG2HKPevBQRzqV0dIJmdW1+gZ13QyIESnQyj9MzGkW4I6MDHXamCZmYAFel2MXtE
|
||||
Vsj7idZCTW/REX/7/z8=
|
||||
-----END CERTIFICATE REQUEST-----
|
18
vendor/swoole/examples/ssl/ssl_passwd/ssl.key
vendored
Executable file
18
vendor/swoole/examples/ssl/ssl_passwd/ssl.key
vendored
Executable file
@ -0,0 +1,18 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,1B8CC4C05815AA64
|
||||
|
||||
i9kRuvTLN6Y329ctDI1Nt0oSRUXqRJo0omtGmLFPA7C8kRs8mwhvpo4G4m8Kh6pf
|
||||
l2fVpaKKVXeQxyTdfgPKPxvGsTODp3ZHODLuKswwj0ERPrjfzsDvKboEYdooC7FF
|
||||
3oYpy33I6XtA3qytkqP/gCCoF9zNaFSlHUGup7ZjEZCO4rEYZmbqtW6CPn9lMNCd
|
||||
DgTl2oNa3t6wopQYRFg3uR8NUSeTjpy0fdWIU5GTWJAw7UEaHslnxeRJlwUHdoiY
|
||||
nG37EJpDgAiDspbHfWN3sfRnRDtL0gcvFy8yzSJr/mzlIdhmuxkAvlHFQ7dtav0+
|
||||
VnaR32lNWWgJVUljnTsPPAAIpznVIaj1aXA32X/N12JWXkr2Pe64uSD0DPE8I9xM
|
||||
l/n2kaSBiiZR7MIXw1wrbLGwN55qZlc9hURlWEE6vlxEz2LFfuMX9wpN/OZtiPpA
|
||||
FdVz+0CojiLsjjBa1ayjinEW6ICPfOJFe8IhCEThF/O1bvkCuUK8edZBUd2JtChA
|
||||
RN1BuX+AwaUryvf93xrqNJ0xxK5mOICCUQi8lYCl/n9bpCJ4HCqfsUiqd4tLy8GO
|
||||
bXx22debalaoYIC3tBz26BY3HbZldDO7LQWvkxkAqK24T26NS/oLagWB8BmGHwwK
|
||||
vi6L++VHFEvfmHNmltmpkM/wjsFw6m5jg8t0ETlYffJTJdlb/1r48/R0U/1dh8Oe
|
||||
n5ymUXYs3KWGVKxZcC7nMzOwisyWI83tm3/Ifytbo1oX1Wk8UL0eQVPbcttAnKAO
|
||||
543Fjs6tfhKUGiOSkvadYLOz08p3BlnXGLbbfdeOZ5b714guzdIHTg==
|
||||
-----END RSA PRIVATE KEY-----
|
25
vendor/swoole/examples/ssl/stream_client.php
vendored
Executable file
25
vendor/swoole/examples/ssl/stream_client.php
vendored
Executable file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
$contextOptions = [
|
||||
'ssl' => [
|
||||
'verify_peer' => false,
|
||||
// 'allow_self_signed' => true,
|
||||
// 'cafile' => __DIR__.'/privkey.pem',
|
||||
'peer_name' => 'example.com',
|
||||
]
|
||||
];
|
||||
$context = stream_context_create($contextOptions);
|
||||
|
||||
$fp = stream_socket_client("ssl://127.0.0.1:9501", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
|
||||
if (!$fp)
|
||||
{
|
||||
die("Unable to connect: $errstr ($errno)");
|
||||
}
|
||||
|
||||
stream_socket_enable_crypto($fp, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
|
||||
$ret = fwrite($fp, "hello\n");
|
||||
var_dump($ret);
|
||||
|
||||
$recv = fread($fp, 8192);
|
||||
var_dump($recv);
|
||||
echo "finish\n";
|
||||
|
30
vendor/swoole/examples/ssl/webserver.php
vendored
Executable file
30
vendor/swoole/examples/ssl/webserver.php
vendored
Executable file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
//$serv = new swoole_http_server("0.0.0.0", 443, SWOOLE_PROCESS, SWOOLE_SOCK_TCP | SWOOLE_SSL);
|
||||
$serv = new swoole_http_server("0.0.0.0", 9501, SWOOLE_BASE, SWOOLE_SOCK_TCP | SWOOLE_SSL);
|
||||
$serv->set([
|
||||
'ssl_cert_file' => __DIR__ . '/ssl.crt',
|
||||
'ssl_key_file' => __DIR__ . '/ssl.key',
|
||||
//'ssl_method' => SWOOLE_TLSv1_2_SERVER_METHOD,
|
||||
'worker_num' => 1,
|
||||
'open_http2_protocol' => true,
|
||||
//'ssl_client_cert_file' => __DIR__ . '/ca.crt',
|
||||
//'ssl_verify_depth' => 10,
|
||||
]);
|
||||
//c158354564362fcc
|
||||
|
||||
$serv->on('Request', function(swoole_http_request $request, swoole_http_response $response) {
|
||||
//var_dump($request->get);
|
||||
//var_dump($request->post);
|
||||
//var_dump($request->cookie);
|
||||
//var_dump($request->files);
|
||||
// var_dump($request->header);
|
||||
// var_dump($request->server);
|
||||
//global $serv;
|
||||
//$info= $serv->getClientInfo($request->fd);
|
||||
// var_dump($info);
|
||||
//$response->cookie("User", "Swoole");
|
||||
//$response->header("X-Server", "Swoole");
|
||||
$response->end("<h1>Hello Swoole!</h1>\n");
|
||||
});
|
||||
|
||||
$serv->start();
|
19
vendor/swoole/examples/ssl/websocket_client.html
vendored
Executable file
19
vendor/swoole/examples/ssl/websocket_client.html
vendored
Executable file
@ -0,0 +1,19 @@
|
||||
<script>
|
||||
var wsServer = 'wss://localhost:9502';
|
||||
var websocket = new WebSocket(wsServer);
|
||||
websocket.onopen = function (evt) {
|
||||
console.log("Connected to WebSocket server.");
|
||||
};
|
||||
|
||||
websocket.onclose = function (evt) {
|
||||
console.log("Disconnected");
|
||||
};
|
||||
|
||||
websocket.onmessage = function (evt) {
|
||||
console.log('Retrieved data from server: ' + evt.data);
|
||||
};
|
||||
|
||||
websocket.onerror = function (evt, e) {
|
||||
console.log('Error occured: ' + evt.data);
|
||||
};
|
||||
</script>
|
42
vendor/swoole/examples/ssl/websocket_server.php
vendored
Executable file
42
vendor/swoole/examples/ssl/websocket_server.php
vendored
Executable file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
$ssl_dir = realpath('../../tests/ssl');
|
||||
$serv = new swoole_websocket_server("0.0.0.0", 9502, SWOOLE_BASE, SWOOLE_SOCK_TCP | SWOOLE_SSL);
|
||||
//$serv = new swoole_websocket_server("0.0.0.0", 9502, SWOOLE_PROCESS, SWOOLE_SOCK_TCP | SWOOLE_SSL);
|
||||
$serv->set([
|
||||
'ssl_cert_file' => $ssl_dir . '/ssl.crt',
|
||||
'ssl_key_file' => $ssl_dir . '/ssl.key',
|
||||
'worker_num' => 1,
|
||||
]);
|
||||
|
||||
$port = $serv->listen('127.0.0.1', 9501, SWOOLE_SOCK_TCP);
|
||||
$port->on('receive', function($serv, $fd, $reactor_id, $data){
|
||||
var_dump($fd, $reactor_id, $data);
|
||||
$serv->send($fd, "Swoole: $data");
|
||||
});
|
||||
|
||||
$serv->on('connect', function ($_server, $fd) {
|
||||
echo "client {$fd} connect\n";
|
||||
});
|
||||
|
||||
$serv->on('open', function (swoole_websocket_server $_server, swoole_http_request $request) {
|
||||
echo "server#{$_server->worker_pid}: handshake success with fd#{$request->fd}\n";
|
||||
// var_dump($request);
|
||||
});
|
||||
|
||||
$serv->on('request', function ($req, $resp) {
|
||||
$resp->end(file_get_contents(__DIR__.'/websocket_client.html'));
|
||||
});
|
||||
|
||||
$serv->on('message', function (swoole_websocket_server $_server, $frame) {
|
||||
var_dump($frame->data);
|
||||
echo "received ".strlen($frame->data)." bytes\n";
|
||||
$_send = str_repeat('B', rand(100, 800));
|
||||
$_server->push($frame->fd, $_send);
|
||||
// echo "#$i\tserver sent " . strlen($_send) . " byte \n";
|
||||
});
|
||||
|
||||
$serv->on('close', function ($_server, $fd) {
|
||||
echo "client {$fd} closed\n";
|
||||
});
|
||||
|
||||
$serv->start();
|
Reference in New Issue
Block a user