Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
c386ec76
D
Docs
项目概览
OpenHarmony
/
Docs
大约 1 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c386ec76
编写于
7月 19, 2023
作者:
X
xujie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加TLS服务端md
Signed-off-by:
N
xujie
<
xujie223@huawei.com
>
上级
7288f283
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
638 addition
and
11 deletion
+638
-11
zh-cn/application-dev/reference/apis/js-apis-socket.md
zh-cn/application-dev/reference/apis/js-apis-socket.md
+638
-11
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-socket.md
浏览文件 @
c386ec76
...
@@ -3952,6 +3952,9 @@ getState(callback: AsyncCallback\<SocketStateBase\>): void
...
@@ -3952,6 +3952,9 @@ getState(callback: AsyncCallback\<SocketStateBase\>): void
在TLSSocketServer的listen成功之后,获取TLSSocketServer状态。使用callback方式作为异步方法。
在TLSSocketServer的listen成功之后,获取TLSSocketServer状态。使用callback方式作为异步方法。
> **说明:**
> listen方法调用成功后,才可调用此方法。
**系统能力**
:SystemCapability.Communication.NetStack
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
**参数:**
...
@@ -3992,6 +3995,7 @@ let options = {
...
@@ -3992,6 +3995,7 @@ let options = {
};
};
tlsServer
.
listen
(
options
,
err
=>
{
tlsServer
.
listen
(
options
,
err
=>
{
console
.
log
(
"
listen callback error
"
+
err
);
console
.
log
(
"
listen callback error
"
+
err
);
return
;
});
});
tlsServer
.
getState
((
err
,
data
)
=>
{
tlsServer
.
getState
((
err
,
data
)
=>
{
...
@@ -4009,6 +4013,9 @@ getState(): Promise\<SocketStateBase\>
...
@@ -4009,6 +4013,9 @@ getState(): Promise\<SocketStateBase\>
在TLSSocketServer的listen成功之后,获取TLSSocketServer状态。使用Promise方式作为异步方法。
在TLSSocketServer的listen成功之后,获取TLSSocketServer状态。使用Promise方式作为异步方法。
> **说明:**
> listen方法调用成功后,才可调用此方法。
**系统能力**
:SystemCapability.Communication.NetStack
**系统能力**
:SystemCapability.Communication.NetStack
**返回值:**
**返回值:**
...
@@ -4050,6 +4057,7 @@ tlsServer.listen(options).then(() => {
...
@@ -4050,6 +4057,7 @@ tlsServer.listen(options).then(() => {
console
.
log
(
"
listen callback success
"
);
console
.
log
(
"
listen callback success
"
);
}).
catch
(
err
=>
{
}).
catch
(
err
=>
{
console
.
log
(
err
);
console
.
log
(
err
);
return
;
});
});
let
promise
=
tlsServer
.
getState
();
let
promise
=
tlsServer
.
getState
();
promise
.
then
(()
=>
{
promise
.
then
(()
=>
{
...
@@ -4065,6 +4073,9 @@ setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void
...
@@ -4065,6 +4073,9 @@ setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void
在TLSSocketServer的listen成功之后,设置TLSSocketServer连接的其他属性。使用callback方式作为异步方法。
在TLSSocketServer的listen成功之后,设置TLSSocketServer连接的其他属性。使用callback方式作为异步方法。
> **说明:**
> listen方法调用成功后,才可调用此方法。
**系统能力**
:SystemCapability.Communication.NetStack
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
**参数:**
...
@@ -4106,6 +4117,7 @@ let options = {
...
@@ -4106,6 +4117,7 @@ let options = {
};
};
tlsServer
.
listen
(
options
,
err
=>
{
tlsServer
.
listen
(
options
,
err
=>
{
console
.
log
(
"
listen callback error
"
+
err
);
console
.
log
(
"
listen callback error
"
+
err
);
return
;
});
});
tlsServer
.
setExtraOptions
({
tlsServer
.
setExtraOptions
({
keepAlive
:
true
,
keepAlive
:
true
,
...
@@ -4131,6 +4143,9 @@ setExtraOptions(options: TCPExtraOptions): Promise\<void\>
...
@@ -4131,6 +4143,9 @@ setExtraOptions(options: TCPExtraOptions): Promise\<void\>
在TLSSocketServer的listen成功之后,设置TLSSocketServer连接的其他属性,使用Promise方式作为异步方法。
在TLSSocketServer的listen成功之后,设置TLSSocketServer连接的其他属性,使用Promise方式作为异步方法。
> **说明:**
> listen方法调用成功后,才可调用此方法。
**系统能力**
:SystemCapability.Communication.NetStack
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
**参数:**
...
@@ -4179,6 +4194,7 @@ tlsServer.listen(options).then(() => {
...
@@ -4179,6 +4194,7 @@ tlsServer.listen(options).then(() => {
console
.
log
(
"
listen callback success
"
);
console
.
log
(
"
listen callback success
"
);
}).
catch
(
err
=>
{
}).
catch
(
err
=>
{
console
.
log
(
err
);
console
.
log
(
err
);
return
;
});
});
let
promise
=
tlsServer
.
setExtraOptions
({
let
promise
=
tlsServer
.
setExtraOptions
({
keepAlive
:
true
,
keepAlive
:
true
,
...
@@ -4203,6 +4219,9 @@ getCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata9)\>):
...
@@ -4203,6 +4219,9 @@ getCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata9)\>):
在TLSSocketServer通信连接成功之后,获取本地的数字证书,使用callback方式作为异步方法。
在TLSSocketServer通信连接成功之后,获取本地的数字证书,使用callback方式作为异步方法。
> **说明:**
> listen方法调用成功后,才可调用此方法。
**系统能力**
:SystemCapability.Communication.NetStack
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
**参数:**
...
@@ -4224,6 +4243,28 @@ getCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata9)\>):
...
@@ -4224,6 +4243,28 @@ getCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata9)\>):
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
192.168.xx.xxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
,
err
=>
{
console
.
log
(
"
listen callback error
"
+
err
);
return
;
});
tlsServer
.
getCertificate
((
err
,
data
)
=>
{
tlsServer
.
getCertificate
((
err
,
data
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
log
(
"
getCertificate callback error =
"
+
err
);
console
.
log
(
"
getCertificate callback error =
"
+
err
);
...
@@ -4239,6 +4280,9 @@ getCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\>
...
@@ -4239,6 +4280,9 @@ getCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\>
在TLSSocketServer通信连接之后,获取本地的数字证书,使用Promise方式作为异步方法。
在TLSSocketServer通信连接之后,获取本地的数字证书,使用Promise方式作为异步方法。
> **说明:**
> listen方法调用成功后,才可调用此方法。
**系统能力**
:SystemCapability.Communication.NetStack
**系统能力**
:SystemCapability.Communication.NetStack
**返回值:**
**返回值:**
...
@@ -4259,6 +4303,30 @@ getCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\>
...
@@ -4259,6 +4303,30 @@ getCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\>
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
xxxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
).
then
(()
=>
{
console
.
log
(
"
listen callback success
"
);
}).
catch
(
err
=>
{
console
.
log
(
err
);
return
;
});
tlsServer
.
getCertificate
().
then
(
data
=>
{
tlsServer
.
getCertificate
().
then
(
data
=>
{
console
.
log
(
data
);
console
.
log
(
data
);
}).
catch
(
err
=>
{
}).
catch
(
err
=>
{
...
@@ -4272,6 +4340,9 @@ getProtocol(callback: AsyncCallback\<string\>): void
...
@@ -4272,6 +4340,9 @@ getProtocol(callback: AsyncCallback\<string\>): void
在TLSSocketServer通信连接成功之后,获取通信的协议版本,使用callback方式作为异步方法。
在TLSSocketServer通信连接成功之后,获取通信的协议版本,使用callback方式作为异步方法。
> **说明:**
> listen方法调用成功后,才可调用此方法。
**系统能力**
:SystemCapability.Communication.NetStack
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
**参数:**
...
@@ -4293,6 +4364,28 @@ getProtocol(callback: AsyncCallback\<string\>): void
...
@@ -4293,6 +4364,28 @@ getProtocol(callback: AsyncCallback\<string\>): void
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
192.168.xx.xxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
,
err
=>
{
console
.
log
(
"
listen callback error
"
+
err
);
return
;
});
tlsServer
.
getProtocol
((
err
,
data
)
=>
{
tlsServer
.
getProtocol
((
err
,
data
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
log
(
"
getProtocol callback error =
"
+
err
);
console
.
log
(
"
getProtocol callback error =
"
+
err
);
...
@@ -4308,6 +4401,9 @@ getProtocol():Promise\<string\>
...
@@ -4308,6 +4401,9 @@ getProtocol():Promise\<string\>
在TLSSocketServer通信连接成功之后,获取通信的协议版本,使用Promise方式作为异步方法。
在TLSSocketServer通信连接成功之后,获取通信的协议版本,使用Promise方式作为异步方法。
> **说明:**
> listen方法调用成功后,才可调用此方法。
**系统能力**
:SystemCapability.Communication.NetStack
**系统能力**
:SystemCapability.Communication.NetStack
**返回值:**
**返回值:**
...
@@ -4328,6 +4424,28 @@ getProtocol():Promise\<string\>
...
@@ -4328,6 +4424,28 @@ getProtocol():Promise\<string\>
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
192.168.xx.xxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
,
err
=>
{
console
.
log
(
"
listen callback error
"
+
err
);
return
;
});
tlsServer
.
getProtocol
().
then
(
data
=>
{
tlsServer
.
getProtocol
().
then
(
data
=>
{
console
.
log
(
data
);
console
.
log
(
data
);
}).
catch
(
err
=>
{
}).
catch
(
err
=>
{
...
@@ -4341,6 +4459,9 @@ on(type: 'connect', callback: Callback\<TLSSocketConnection\>): void
...
@@ -4341,6 +4459,9 @@ on(type: 'connect', callback: Callback\<TLSSocketConnection\>): void
订阅TLSSocketServer的连接事件。使用callback方式作为异步方法。
订阅TLSSocketServer的连接事件。使用callback方式作为异步方法。
> **说明:**
> listen方法调用成功后,才可调用此方法。
**系统能力**
:SystemCapability.Communication.NetStack
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
**参数:**
...
@@ -4360,6 +4481,28 @@ on(type: 'connect', callback: Callback\<TLSSocketConnection\>): void
...
@@ -4360,6 +4481,28 @@ on(type: 'connect', callback: Callback\<TLSSocketConnection\>): void
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
192.168.xx.xxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
,
err
=>
{
console
.
log
(
"
listen callback error
"
+
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
function
(
data
)
{
tlsServer
.
on
(
'
connect
'
,
function
(
data
)
{
console
.
log
(
JSON
.
stringify
(
data
))
console
.
log
(
JSON
.
stringify
(
data
))
});
});
...
@@ -4396,6 +4539,30 @@ let tlsServer = socket.constructTLSSocketServerInstance();
...
@@ -4396,6 +4539,30 @@ let tlsServer = socket.constructTLSSocketServerInstance();
let
callback
=
data
=>
{
let
callback
=
data
=>
{
console
.
log
(
'
on connect message:
'
+
JSON
.
stringify
(
data
));
console
.
log
(
'
on connect message:
'
+
JSON
.
stringify
(
data
));
}
}
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
xxxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
).
then
(()
=>
{
console
.
log
(
"
listen callback success
"
);
}).
catch
(
err
=>
{
console
.
log
(
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
callback
);
tlsServer
.
on
(
'
connect
'
,
callback
);
// 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
// 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
tlsServer
.
off
(
'
connect
'
,
callback
);
tlsServer
.
off
(
'
connect
'
,
callback
);
...
@@ -4427,6 +4594,28 @@ on(type: 'error', callback: ErrorCallback): void
...
@@ -4427,6 +4594,28 @@ on(type: 'error', callback: ErrorCallback): void
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
192.168.xx.xxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
,
err
=>
{
console
.
log
(
"
listen callback error
"
+
err
);
return
;
});
tlsServer
.
on
(
'
error
'
,
err
=>
{
tlsServer
.
on
(
'
error
'
,
err
=>
{
console
.
log
(
"
on error, err:
"
+
JSON
.
stringify
(
err
))
console
.
log
(
"
on error, err:
"
+
JSON
.
stringify
(
err
))
});
});
...
@@ -4463,6 +4652,30 @@ let tlsServer = socket.constructTLSSocketServerInstance();
...
@@ -4463,6 +4652,30 @@ let tlsServer = socket.constructTLSSocketServerInstance();
let
callback
=
err
=>
{
let
callback
=
err
=>
{
console
.
log
(
"
on error, err:
"
+
JSON
.
stringify
(
err
));
console
.
log
(
"
on error, err:
"
+
JSON
.
stringify
(
err
));
}
}
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
xxxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
).
then
(()
=>
{
console
.
log
(
"
listen callback success
"
);
}).
catch
(
err
=>
{
console
.
log
(
err
);
return
;
});
tlsServer
.
on
(
'
error
'
,
callback
);
tlsServer
.
on
(
'
error
'
,
callback
);
// 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
// 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
tlsServer
.
off
(
'
error
'
,
callback
);
tlsServer
.
off
(
'
error
'
,
callback
);
...
@@ -4514,6 +4727,28 @@ send(data: string, callback: AsyncCallback\<void\>): void
...
@@ -4514,6 +4727,28 @@ send(data: string, callback: AsyncCallback\<void\>): void
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
192.168.xx.xxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
,
err
=>
{
console
.
log
(
"
listen callback error
"
+
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
client
.
send
({
data
:
'
Hello, client!
'
},
err
=>
{
client
.
send
({
data
:
'
Hello, client!
'
},
err
=>
{
if
(
err
)
{
if
(
err
)
{
...
@@ -4560,27 +4795,51 @@ send(data: string): Promise\<void\>
...
@@ -4560,27 +4795,51 @@ send(data: string): Promise\<void\>
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
let
options
=
{
let
promise
=
client
.
send
({
data
:
'
Hello, client!
'
});
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
promise
.
then
(()
=>
{
address
:
{
console
.
log
(
'
send success
'
);
address
:
"
xxxx
"
,
}).
catch
(
err
=>
{
port
:
8080
,
console
.
log
(
'
send fail
'
);
family
:
1
,
});
},
});
secureOptions
:
{
```
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
### close<sup>10+</sup>
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
close(callback: AsyncCallback
\<
void
\>
): void
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
在与TLSSocketServer通信连接成功之后,断开连接,使用callback方式作为异步方法。
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
**系统能力**
:SystemCapability.Communication.NetStack
},
};
**参数:**
tlsServer
.
listen
(
options
).
then
(()
=>
{
console
.
log
(
"
listen callback success
"
);
| 参数名 | 类型 | 必填 | 说明 |
}).
catch
(
err
=>
{
console
.
log
(
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
let
promise
=
client
.
send
({
data
:
'
Hello, client!
'
});
promise
.
then
(()
=>
{
console
.
log
(
'
send success
'
);
}).
catch
(
err
=>
{
console
.
log
(
'
send fail
'
);
});
});
```
### close<sup>10+</sup>
close(callback: AsyncCallback
\<
void
\>
): void
在与TLSSocketServer通信连接成功之后,断开连接,使用callback方式作为异步方法。
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------- | ---- | ------------------------------------------------ |
| -------- | --------------------- | ---- | ------------------------------------------------ |
| callback | AsyncCallback
\<
void
\>
| 是 | 回调函数,成功返回空,失败返回错误码,错误信息。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 回调函数,成功返回空,失败返回错误码,错误信息。 |
...
@@ -4598,6 +4857,28 @@ close(callback: AsyncCallback\<void\>): void
...
@@ -4598,6 +4857,28 @@ close(callback: AsyncCallback\<void\>): void
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
192.168.xx.xxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
,
err
=>
{
console
.
log
(
"
listen callback error
"
+
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
client
.
close
(
err
=>
{
client
.
close
(
err
=>
{
if
(
err
)
{
if
(
err
)
{
...
@@ -4636,6 +4917,30 @@ close(): Promise\<void\>
...
@@ -4636,6 +4917,30 @@ close(): Promise\<void\>
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
xxxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
).
then
(()
=>
{
console
.
log
(
"
listen callback success
"
);
}).
catch
(
err
=>
{
console
.
log
(
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
let
promise
=
client
.
close
();
let
promise
=
client
.
close
();
promise
.
then
(()
=>
{
promise
.
then
(()
=>
{
...
@@ -4672,6 +4977,28 @@ getRemoteAddress(callback: AsyncCallback\<NetAddress\>): void
...
@@ -4672,6 +4977,28 @@ getRemoteAddress(callback: AsyncCallback\<NetAddress\>): void
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
192.168.xx.xxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
,
err
=>
{
console
.
log
(
"
listen callback error
"
+
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
client
.
getRemoteAddress
((
err
,
data
)
=>
{
client
.
getRemoteAddress
((
err
,
data
)
=>
{
if
(
err
)
{
if
(
err
)
{
...
@@ -4708,6 +5035,30 @@ getRemoteAddress(): Promise\<NetAddress\>
...
@@ -4708,6 +5035,30 @@ getRemoteAddress(): Promise\<NetAddress\>
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
xxxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
).
then
(()
=>
{
console
.
log
(
"
listen callback success
"
);
}).
catch
(
err
=>
{
console
.
log
(
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
client
.
getRemoteAddress
().
then
(
data
=>
{
client
.
getRemoteAddress
().
then
(
data
=>
{
console
.
log
(
'
getRemoteAddress success:
'
+
JSON
.
stringify
(
data
));
console
.
log
(
'
getRemoteAddress success:
'
+
JSON
.
stringify
(
data
));
...
@@ -4743,6 +5094,28 @@ getRemoteCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata
...
@@ -4743,6 +5094,28 @@ getRemoteCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
192.168.xx.xxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
,
err
=>
{
console
.
log
(
"
listen callback error
"
+
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
client
.
getRemoteCertificate
((
err
,
data
)
=>
{
client
.
getRemoteCertificate
((
err
,
data
)
=>
{
if
(
err
)
{
if
(
err
)
{
...
@@ -4779,6 +5152,30 @@ getRemoteCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\>
...
@@ -4779,6 +5152,30 @@ getRemoteCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\>
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
xxxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
).
then
(()
=>
{
console
.
log
(
"
listen callback success
"
);
}).
catch
(
err
=>
{
console
.
log
(
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
client
.
getRemoteCertificate
().
then
(
data
=>
{
client
.
getRemoteCertificate
().
then
(
data
=>
{
console
.
log
(
'
getRemoteCertificate success:
'
+
JSON
.
stringify
(
data
));
console
.
log
(
'
getRemoteCertificate success:
'
+
JSON
.
stringify
(
data
));
...
@@ -4816,6 +5213,28 @@ getCipherSuite(callback: AsyncCallback\<Array\<string\>\>): void
...
@@ -4816,6 +5213,28 @@ getCipherSuite(callback: AsyncCallback\<Array\<string\>\>): void
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
192.168.xx.xxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
,
err
=>
{
console
.
log
(
"
listen callback error
"
+
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
client
.
getCipherSuite
((
err
,
data
)
=>
{
client
.
getCipherSuite
((
err
,
data
)
=>
{
if
(
err
)
{
if
(
err
)
{
...
@@ -4854,6 +5273,30 @@ getCipherSuite(): Promise\<Array\<string\>\>
...
@@ -4854,6 +5273,30 @@ getCipherSuite(): Promise\<Array\<string\>\>
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
xxxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
).
then
(()
=>
{
console
.
log
(
"
listen callback success
"
);
}).
catch
(
err
=>
{
console
.
log
(
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
client
.
getCipherSuite
().
then
(
data
=>
{
client
.
getCipherSuite
().
then
(
data
=>
{
console
.
log
(
'
getCipherSuite success:
'
+
JSON
.
stringify
(
data
));
console
.
log
(
'
getCipherSuite success:
'
+
JSON
.
stringify
(
data
));
...
@@ -4889,6 +5332,28 @@ getSignatureAlgorithms(callback: AsyncCallback\<Array\<string\>\>): void
...
@@ -4889,6 +5332,28 @@ getSignatureAlgorithms(callback: AsyncCallback\<Array\<string\>\>): void
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
192.168.xx.xxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
,
err
=>
{
console
.
log
(
"
listen callback error
"
+
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
client
.
getSignatureAlgorithms
((
err
,
data
)
=>
{
client
.
getSignatureAlgorithms
((
err
,
data
)
=>
{
if
(
err
)
{
if
(
err
)
{
...
@@ -4925,6 +5390,30 @@ getSignatureAlgorithms(): Promise\<Array\<string\>\>
...
@@ -4925,6 +5390,30 @@ getSignatureAlgorithms(): Promise\<Array\<string\>\>
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
xxxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
).
then
(()
=>
{
console
.
log
(
"
listen callback success
"
);
}).
catch
(
err
=>
{
console
.
log
(
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
client
.
getSignatureAlgorithms
().
then
(
data
=>
{
client
.
getSignatureAlgorithms
().
then
(
data
=>
{
console
.
log
(
"
getSignatureAlgorithms success
"
+
data
);
console
.
log
(
"
getSignatureAlgorithms success
"
+
data
);
...
@@ -4959,6 +5448,28 @@ on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: Socket
...
@@ -4959,6 +5448,28 @@ on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: Socket
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
192.168.xx.xxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
,
err
=>
{
console
.
log
(
"
listen callback error
"
+
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
client
.
on
(
'
message
'
,
value
=>
{
client
.
on
(
'
message
'
,
value
=>
{
let
messageView
=
''
;
let
messageView
=
''
;
...
@@ -5011,6 +5522,30 @@ let callback = value => {
...
@@ -5011,6 +5522,30 @@ let callback = value => {
console
.
log
(
'
remoteInfo:
'
+
JSON
.
stringify
(
value
.
remoteInfo
));
console
.
log
(
'
remoteInfo:
'
+
JSON
.
stringify
(
value
.
remoteInfo
));
}
}
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
xxxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
).
then
(()
=>
{
console
.
log
(
"
listen callback success
"
);
}).
catch
(
err
=>
{
console
.
log
(
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
client
.
on
(
'
message
'
,
callback
);
client
.
on
(
'
message
'
,
callback
);
// 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
// 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
...
@@ -5044,6 +5579,28 @@ on(type: 'close', callback: Callback\<void\>): void
...
@@ -5044,6 +5579,28 @@ on(type: 'close', callback: Callback\<void\>): void
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
192.168.xx.xxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
,
err
=>
{
console
.
log
(
"
listen callback error
"
+
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
client
.
on
(
'
close
'
,
()
=>
{
client
.
on
(
'
close
'
,
()
=>
{
console
.
log
(
"
on close success
"
)
console
.
log
(
"
on close success
"
)
...
@@ -5082,6 +5639,30 @@ let callback = () => {
...
@@ -5082,6 +5639,30 @@ let callback = () => {
console
.
log
(
"
on close success
"
);
console
.
log
(
"
on close success
"
);
}
}
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
xxxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
).
then
(()
=>
{
console
.
log
(
"
listen callback success
"
);
}).
catch
(
err
=>
{
console
.
log
(
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
client
.
on
(
'
close
'
,
callback
);
client
.
on
(
'
close
'
,
callback
);
// 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
// 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
...
@@ -5115,6 +5696,28 @@ on(type: 'error', callback: ErrorCallback): void
...
@@ -5115,6 +5696,28 @@ on(type: 'error', callback: ErrorCallback): void
```
js
```
js
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
192.168.xx.xxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
,
err
=>
{
console
.
log
(
"
listen callback error
"
+
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
client
.
on
(
'
error
'
,
err
=>
{
client
.
on
(
'
error
'
,
err
=>
{
console
.
log
(
"
on error, err:
"
+
JSON
.
stringify
(
err
))
console
.
log
(
"
on error, err:
"
+
JSON
.
stringify
(
err
))
...
@@ -5153,6 +5756,30 @@ let callback = err => {
...
@@ -5153,6 +5756,30 @@ let callback = err => {
console
.
log
(
"
on error, err:
"
+
JSON
.
stringify
(
err
));
console
.
log
(
"
on error, err:
"
+
JSON
.
stringify
(
err
));
}
}
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
tlsServer
=
socket
.
constructTLSSocketServerInstance
();
let
options
=
{
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
xxxx
"
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
key
:
"
xxxx
"
,
cert
:
"
xxxx
"
,
ca
:
[
"
xxxx
"
],
password
:
"
xxxx
"
,
protocols
:
[
socket
.
Protocol
.
TLSv12
],
useRemoteCipherPrefer
:
true
,
signatureAlgorithms
:
"
rsa_pss_rsae_sha256:ECDSA+SHA256
"
,
cipherSuite
:
"
AES256-SHA256
"
,
},
};
tlsServer
.
listen
(
options
).
then
(()
=>
{
console
.
log
(
"
listen callback success
"
);
}).
catch
(
err
=>
{
console
.
log
(
err
);
return
;
});
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
tlsServer
.
on
(
'
connect
'
,
function
(
client
)
{
client
.
on
(
'
error
'
,
callback
);
client
.
on
(
'
error
'
,
callback
);
// 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
// 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录