Skip to content

Commit 37ca579

Browse files
committed
update, some logic mofify
1 parent 8d0b1dc commit 37ca579

19 files changed

+230
-41
lines changed
File renamed without changes.

docs/referrer/websocket.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Websocket协议通过序列化的数据帧传输数据。数据封包协议中
1010

1111
针对上情况,发现错误的一方可向对方发送close帧(状态码是1002,表示协议错误),以关闭连接。
1212

13-
![](examples/assets/images/ws-data-framing.png)
13+
![](images/ws-data-framing.png)
1414

1515
详细说明:
1616

examples/app_server

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
require __DIR__ . '/../../../autoload.php';
1212

13-
use inhere\webSocket\server\Application;
13+
use inhere\webSocket\Application;
1414
use inhere\webSocket\http\Request;
15-
use inhere\webSocket\server\handlers\RouteHandlerInterface;
15+
use inhere\webSocket\handlers\RouteHandlerInterface;
1616

1717
define('PROJECT_PATH', __DIR__);
1818

@@ -34,7 +34,7 @@ $app->onClose(function (Application $app, int $id, array $client) {
3434
]);
3535
});
3636

37-
$rootHandler = $app->route('/', new \inhere\webSocket\server\handlers\RootHandler());
37+
$rootHandler = $app->route('/', new \inhere\webSocket\handlers\RootHandler());
3838

3939
// commands
4040
$rootHandler->add('test', function ($data, $index, RouteHandlerInterface $handler) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: inhere
5+
* Date: 2017-08-17
6+
* Time: 9:44
7+
*/
8+
9+
namespace inhere\webSocket\examples\charRoom\webSite;
10+
11+
12+
class ChatRoom
13+
{
14+
15+
}
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@
66
* Time: 23:13
77
*/
88

9-
namespace inhere\webSocket\server;
9+
namespace inhere\webSocket;
1010

1111
use inhere\console\io\Input;
1212
use inhere\console\io\Output;
1313
use inhere\library\helpers\PhpHelper;
1414
use inhere\library\helpers\ProcessHelper;
1515
use inhere\library\traits\OptionsTrait;
1616
use inhere\library\utils\LiteLogger;
17-
use inhere\webSocket\server\handlers\RouteHandlerInterface;
18-
use inhere\webSocket\server\handlers\RootHandler;
19-
use inhere\webSocket\parts\MessageBag;
17+
use inhere\webSocket\handlers\RouteHandlerInterface;
18+
use inhere\webSocket\handlers\RootHandler;
19+
use inhere\webSocket\http\WSResponse;
2020
use inhere\webSocket\http\Request;
2121
use inhere\webSocket\http\Response;
22-
use inhere\webSocket\WSInterface;
22+
use inhere\webSocket\server\ServerAbstracter;
23+
use inhere\webSocket\server\ServerFactory;
24+
use inhere\webSocket\server\ServerInterface;
2325

2426
/**
2527
* Class Application
@@ -637,7 +639,7 @@ public function buildMessage($data, string $msg = 'success', int $code = 0)
637639
* @param string $msg
638640
* @param int $code
639641
* @param bool $doSend
640-
* @return int|MessageBag
642+
* @return int|WSResponse
641643
*/
642644
public function respond($data, string $msg = '', int $code = 0, bool $doSend = true)
643645
{
@@ -650,15 +652,15 @@ public function respond($data, string $msg = '', int $code = 0, bool $doSend = t
650652
* response text data to client
651653
* @param $data
652654
* @param bool $doSend
653-
* @return int|MessageBag
655+
* @return int|WSResponse
654656
*/
655657
public function respondText($data, bool $doSend = true)
656658
{
657659
if (is_array($data)) {
658660
$data = implode('', $data);
659661
}
660662

661-
$mr = MessageBag::make($data)->setWs($this->ws);
663+
$mr = WSResponse::make($data)->setWs($this->ws);
662664

663665
if ($doSend) {
664666
$mr->send();
@@ -695,7 +697,7 @@ public function sendText($data, \Closure $afterMakeMR = null, bool $reset = true
695697
$data = implode('', $data);
696698
}
697699

698-
$mr = MessageBag::make($data)->setWs($this->ws);
700+
$mr = WSResponse::make($data)->setWs($this->ws);
699701

700702
if ($afterMakeMR) {
701703
$status = $afterMakeMR($mr);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Time: 15:34
77
*/
88

9-
namespace inhere\webSocket\server\handlers;
9+
namespace inhere\webSocket\handlers;
1010

1111
use inhere\webSocket\http\Request;
1212
use inhere\webSocket\http\Response;
@@ -16,7 +16,7 @@
1616
*
1717
* handle the root '/' webSocket request
1818
*
19-
* @package inhere\webSocket\server\handlers
19+
* @package inhere\webSocket\handlers
2020
*/
2121
class RootHandler extends RouteHandlerAbstracter
2222
{

src/server/handlers/RouteHandlerAbstracter.php renamed to src/handlers/RouteHandlerAbstracter.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
* Time: 22:51
77
*/
88

9-
namespace inhere\webSocket\server\handlers;
9+
namespace inhere\webSocket\handlers;
1010

1111
use inhere\library\traits\OptionsTrait;
12-
use inhere\webSocket\server\Application;
12+
use inhere\webSocket\Application;
1313
use inhere\webSocket\server\dataParser\ComplexDataParserInterface;
1414
use inhere\webSocket\server\dataParser\DataParserInterface;
1515
use inhere\webSocket\http\Request;
1616
use inhere\webSocket\http\Response;
17-
use inhere\webSocket\parts\MessageBag;
17+
use inhere\webSocket\http\WSResponse;
1818

1919
/**
2020
* Class ARouteHandler
21-
* @package inhere\webSocket\server\handlers
21+
* @package inhere\webSocket\handlers
2222
*/
2323
abstract class RouteHandlerAbstracter implements RouteHandlerInterface
2424
{
@@ -299,7 +299,7 @@ public function getCmdHandlers(): array
299299
* @param string $msg
300300
* @param int $code
301301
* @param bool $doSend
302-
* @return int|MessageBag
302+
* @return int|WSResponse
303303
*/
304304
public function respond($data, string $msg = 'success', int $code = 0, bool $doSend = true)
305305
{
@@ -309,7 +309,7 @@ public function respond($data, string $msg = 'success', int $code = 0, bool $doS
309309
/**
310310
* @param $data
311311
* @param bool $doSend
312-
* @return MessageBag|int
312+
* @return WSResponse|int
313313
*/
314314
public function respondText($data, bool $doSend = true)
315315
{

src/server/handlers/RouteHandlerInterface.php renamed to src/handlers/RouteHandlerInterface.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
* Time: 15:35
77
*/
88

9-
namespace inhere\webSocket\server\handlers;
9+
namespace inhere\webSocket\handlers;
1010

11-
use inhere\webSocket\server\Application;
11+
use inhere\webSocket\Application;
1212
use inhere\webSocket\http\Request;
1313
use inhere\webSocket\http\Response;
14-
use inhere\webSocket\parts\MessageBag;
14+
use inhere\webSocket\http\WSResponse;
1515

1616
/**
1717
* Interface IRouteHandler
18-
* @package inhere\webSocket\server\handlers
18+
* @package inhere\webSocket\handlers
1919
*/
2020
interface RouteHandlerInterface
2121
{
@@ -75,7 +75,7 @@ public function isJsonType();
7575
* @param string $msg
7676
* @param int $code
7777
* @param bool $doSend
78-
* @return int|MessageBag
78+
* @return int|WSResponse
7979
*/
8080
public function respond($data, string $msg = 'success', int $code = 0, bool $doSend = true);
8181

src/http/WSRequest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: inhere
5+
* Date: 2017-08-17
6+
* Time: 11:08
7+
*/
8+
9+
namespace inhere\webSocket\server;
10+
11+
/**
12+
* Class WSRequest
13+
* @package inhere\webSocket\server
14+
*/
15+
class WSRequest
16+
{
17+
18+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
* Time: 21:32
77
*/
88

9-
namespace inhere\webSocket\parts;
9+
namespace inhere\webSocket\http;
1010

1111
use inhere\library\traits\TraitArrayAccess;
1212
use inhere\library\traits\TraitGetterSetterAccess;
1313
use inhere\webSocket\server\ServerInterface;
1414

1515
/**
16-
* Class MessageResponse
16+
* Class WSResponse
1717
* webSocket message response
1818
* @package inhere\webSocket\parts
1919
*/
20-
class MessageBag implements \ArrayAccess
20+
class WSResponse implements \ArrayAccess
2121
{
2222
use TraitArrayAccess;
2323
use TraitGetterSetterAccess;

0 commit comments

Comments
 (0)