Skip to content

Commit

Permalink
Private and Public channel reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouaini528 committed Jul 13, 2021
1 parent f991d43 commit e4e6db5
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 33 deletions.
27 changes: 15 additions & 12 deletions src/Api/WebSocketV3/SocketClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,21 @@ protected function getData($global,$callback=null,$sub=[]){
return $temp;
}

/*
*
* */
function reconPrivate(string $key){
$this->client->debug=[
'private'=>[$key=>'close'],
];
}

function reconPublic(){
$this->client->debug=[
'public'=>['public'=>'close'],
];
}

function test(){
print_r($this->client->all_sub);
print_r($this->client->add_sub);
Expand All @@ -188,19 +203,7 @@ function test2(){
}
}

function test_reconnection(){
$this->client->debug=[
'public'=>['public'=>'close'],
];
}

function test_reconnection2(){
$this->client->debug2=1;
}

function test_reconnection3($key){
$this->client->debug=[
'private'=>[$key=>'close'],
];
}
}
3 changes: 2 additions & 1 deletion src/Api/WebSocketV3/SocketServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ private function subscribePrivate($con,$global){
//**********判断是否已经登陆
$client_keysecret=$global->get('keysecret');
$keysecret=$con->tag_keysecret;
if($client_keysecret[$keysecret['key']]['login']!=1) {

if($client_keysecret[$keysecret['key']]['login']!=1 || $client_keysecret[$keysecret['key']]['key']!=$con->tag_keysecret['key']) {
$this->log('subscribe private dont login return '.$keysecret['key']);
return;
}
Expand Down
27 changes: 15 additions & 12 deletions src/Api/WebSocketV5/SocketClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,21 @@ protected function getData($global,$callback=null,$sub=[]){
return $temp;
}

/*
*
* */
function reconPrivate(string $key){
$this->client->debug=[
'private'=>[$key=>'close'],
];
}

function reconPublic(){
$this->client->debug=[
'public'=>['public'=>'close'],
];
}

function test(){
echo 'all_sub'.PHP_EOL;
print_r($this->client->all_sub);
Expand All @@ -200,19 +215,7 @@ function test2(){
}
}

function test_reconnection(){
$this->client->debug=[
'public'=>['public'=>'close'],
];
}

function test_reconnection2(){
$this->client->debug2=1;
}

function test_reconnection3($key){
$this->client->debug=[
'private'=>[$key=>'close'],
];
}
}
3 changes: 2 additions & 1 deletion src/Api/WebSocketV5/SocketServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ private function subscribe($con,$global){
//**********判断是否已经登陆
$client_keysecret=$global->get('keysecret');
$keysecret=$con->tag_keysecret;
if($client_keysecret[$keysecret['key']]['login']!=1) {

if($client_keysecret[$keysecret['key']]['login']!=1 || $client_keysecret[$keysecret['key']]['key']!=$con->tag_keysecret['key']) {
$this->log('subscribe private dont login return '.$keysecret['key']);
return;
}
Expand Down
15 changes: 15 additions & 0 deletions src/OkexWebSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,19 @@ public function getSubscribe(array $sub,$callback=null,$daemon=false){
public function getSubscribes($callback=null,$daemon=false){
return $this->client()->getSubscribes($callback,$daemon);
}

/**
* Private channel reconnect
* @param string $key
*/
public function reconPrivate(string $key){
$this->client()->reconPrivate($key);
}

/**
* Public channel reconnect
*/
public function reconPublic(){
$this->client()->reconPublic();
}
}
15 changes: 15 additions & 0 deletions src/OkexWebSocketV5.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,19 @@ public function getSubscribe(array $sub,$callback=null,$daemon=false){
public function getSubscribes($callback=null,$daemon=false){
return $this->client()->getSubscribes($callback,$daemon);
}

/**
* Private channel reconnect
* @param string $key
*/
public function reconPrivate(string $key){
$this->client()->reconPrivate($key);
}

/**
* Public channel reconnect
*/
public function reconPublic(){
$this->client()->reconPublic();
}
}
10 changes: 5 additions & 5 deletions tests/websocket_v3/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//'log'=>['filename'=>'okex'],

//Daemons address and port,default 0.0.0.0:2207
'global'=>'127.0.0.1:22080',
//'global'=>'127.0.0.1:22080',

//Heartbeat time,default 20 seconds
//'ping_time'=>20,
Expand Down Expand Up @@ -70,9 +70,9 @@
case 10:{
$okex->keysecret($key_secret[0]);
$okex->subscribe([
'spot/depth5:BCH-USDT',
/*'spot/depth5:BCH-USDT',
'futures/depth5:BCH-USD-210924',
'swap/depth5:BCH-USD-SWAP',
'swap/depth5:BCH-USD-SWAP',*/

'futures/position:BCH-USD-210924',
'futures/account:BCH-USDT',
Expand Down Expand Up @@ -249,14 +249,14 @@
}

case 10006:{
$okex->client()->test_reconnection2();
$okex->reconPublic();
break;
}

case 10007:{
//private
//print_r($key_secret[0]);
$okex->client()->test_reconnection3($key_secret[0]['key']);
$okex->reconPrivate($key_secret[0]['key']);
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/websocket_v5/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,14 @@
}

case 10006:{
$okex->client()->test_reconnection2();
$okex->reconPublic();
break;
}

case 10007:{
//private
//print_r($key_secret[0]);
$okex->client()->test_reconnection3($key_secret[0]['key']);
$okex->reconPrivate($key_secret[0]['key']);
break;
}
}
Expand Down

0 comments on commit e4e6db5

Please sign in to comment.