Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
10d8e2f8
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
10d8e2f8
编写于
1月 31, 2023
作者:
Z
zhanghaifeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix simple code
Signed-off-by:
N
zhanghaifeng
<
zhanghaifeng11@huawei.com
>
上级
dc20c03b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
118 addition
and
115 deletion
+118
-115
zh-cn/application-dev/reference/apis/js-apis-net-connection.md
.../application-dev/reference/apis/js-apis-net-connection.md
+26
-30
zh-cn/application-dev/reference/apis/js-apis-net-ethernet.md
zh-cn/application-dev/reference/apis/js-apis-net-ethernet.md
+56
-43
zh-cn/application-dev/reference/apis/js-apis-net-sharing.md
zh-cn/application-dev/reference/apis/js-apis-net-sharing.md
+19
-25
zh-cn/application-dev/reference/apis/js-apis-socket.md
zh-cn/application-dev/reference/apis/js-apis-socket.md
+17
-17
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-net-connection.md
浏览文件 @
10d8e2f8
...
...
@@ -881,18 +881,18 @@ bindSocket(socketParam: TCPSocket \| UDPSocket, callback: AsyncCallback\<void>):
```
js
import
socket
from
"
@ohos.net.socket
"
;
connection
.
getDefaultNet
().
then
((
netHandle
)
=>
{
connection
.
getDefaultNet
().
then
((
netHandle
)
=>
{
var
tcp
=
socket
.
constructTCPSocketInstance
();
var
udp
=
socket
.
constructUDPSocketInstance
();
let
socketType
=
"
TCPSocket
"
;
if
(
socketType
==
"
TCPSocket
"
)
{
tcp
.
bind
({
address
:
'
192.168.xx.xxx
'
,
port
:
xxxx
,
family
:
1
},
err
=>
{
if
(
err
)
{
address
:
'
192.168.xx.xxx
'
,
port
:
8080
,
family
:
1
},
err
or
=>
{
if
(
err
or
)
{
console
.
log
(
'
bind fail
'
);
}
netHandle
.
bindSocket
(
tcp
,
(
error
,
data
)
=>
{
netHandle
.
bindSocket
(
tcp
,
(
error
,
data
)
=>
{
if
(
error
)
{
console
.
log
(
JSON
.
stringify
(
error
));
}
else
{
...
...
@@ -902,19 +902,19 @@ connection.getDefaultNet().then((netHandle)=>{
})
}
else
{
let
callback
=
value
=>
{
console
.
log
(
TAG
+
"
on message, message:
"
+
value
.
message
+
"
, remoteInfo:
"
+
value
.
remoteInfo
);
console
.
log
(
"
on message, message:
"
+
value
.
message
+
"
, remoteInfo:
"
+
value
.
remoteInfo
);
}
udp
.
on
(
'
message
'
,
callback
);
udp
.
bind
({
address
:
'
192.168.xx.xxx
'
,
port
:
xxxx
,
family
:
1
},
err
=>
{
if
(
err
)
{
address
:
'
192.168.xx.xxx
'
,
port
:
8080
,
family
:
1
},
err
or
=>
{
if
(
err
or
)
{
console
.
log
(
'
bind fail
'
);
}
udp
.
on
(
'
message
'
,
(
data
)
=>
{
console
.
log
(
JSON
.
stringify
(
data
))
});
netHandle
.
bindSocket
(
udp
,
(
error
,
data
)
=>
{
netHandle
.
bindSocket
(
udp
,
(
error
,
data
)
=>
{
if
(
error
)
{
console
.
log
(
JSON
.
stringify
(
error
));
}
else
{
...
...
@@ -950,45 +950,41 @@ bindSocket(socketParam: TCPSocket \| UDPSocket): Promise\<void>;
```
js
import
socket
from
"
@ohos.net.socket
"
;
connection
.
getDefaultNet
().
then
((
netHandle
)
=>
{
connection
.
getDefaultNet
().
then
((
netHandle
)
=>
{
var
tcp
=
socket
.
constructTCPSocketInstance
();
var
udp
=
socket
.
constructUDPSocketInstance
();
let
socketType
=
"
TCPSocket
"
;
if
(
socketType
==
"
TCPSocket
"
)
{
tcp
.
bind
({
address
:
'
192.168.xx.xxx
'
,
port
:
xxxx
,
family
:
1
},
err
=>
{
if
(
err
)
{
address
:
'
192.168.xx.xxx
'
,
port
:
8080
,
family
:
1
},
err
or
=>
{
if
(
err
or
)
{
console
.
log
(
'
bind fail
'
);
}
netHandle
.
bindSocket
(
tcp
).
then
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
log
(
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
JSON
.
stringify
(
data
));
}
netHandle
.
bindSocket
(
tcp
).
then
((
data
)
=>
{
console
.
log
(
JSON
.
stringify
(
data
));
}).
catch
(
error
=>
{
console
.
log
(
JSON
.
stringify
(
error
));
})
})
}
else
{
let
callback
=
value
=>
{
console
.
log
(
TAG
+
"
on message, message:
"
+
value
.
message
+
"
, remoteInfo:
"
+
value
.
remoteInfo
);
console
.
log
(
"
on message, message:
"
+
value
.
message
+
"
, remoteInfo:
"
+
value
.
remoteInfo
);
}
udp
.
on
(
'
message
'
,
callback
);
udp
.
bind
({
address
:
'
192.168.xx.xxx
'
,
port
:
xxxx
,
family
:
1
},
err
=>
{
if
(
err
)
{
address
:
'
192.168.xx.xxx
'
,
port
:
8080
,
family
:
1
},
err
or
=>
{
if
(
err
or
)
{
console
.
log
(
'
bind fail
'
);
}
udp
.
on
(
'
message
'
,
(
data
)
=>
{
console
.
log
(
JSON
.
stringify
(
data
));
})
netHandle
.
bindSocket
(
udp
).
then
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
log
(
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
JSON
.
stringify
(
data
));
}
netHandle
.
bindSocket
(
udp
).
then
((
data
)
=>
{
console
.
log
(
JSON
.
stringify
(
data
));
}).
catch
(
error
=>
{
console
.
log
(
JSON
.
stringify
(
error
));
})
})
}
...
...
zh-cn/application-dev/reference/apis/js-apis-net-ethernet.md
浏览文件 @
10d8e2f8
...
...
@@ -35,15 +35,21 @@ setIfaceConfig(iface: string, ic: InterfaceConfiguration, callback: AsyncCallbac
**示例:**
```
js
ethernet
.
setIfaceConfig
(
"
eth0
"
,
{
mode
:
ethernet
.
STATIC
,
ipAddr
:
"
192.168.1.123
"
,
routeAddr
:
"
192.168.1.1
"
,
gateAddr
:
"
192.168.1.1
"
,
maskAddr
:
"
255.255.255.0
"
,
dnsAddr0
:
"
1.1.1.1
"
,
dnsAddr1
:
"
2.2.2.2
"
},
(
error
)
=>
{
if
(
error
)
{
console
.
log
(
"
setIfaceConfig callback error =
"
+
error
);
}
else
{
console
.
log
(
"
setIfaceConfig callback ok
"
);
}
});
ethernet
.
setIfaceConfig
(
"
eth0
"
,
{
mode
:
0
,
ipAddr
:
"
192.168.1.123
"
,
route
:
"
192.168.1.1
"
,
gateway
:
"
192.168.1.1
"
,
netMask
:
"
255.255.255.0
"
,
dnsServers
:
"
1.1.1.1
"
,
domain
:
"
2.2.2.2
"
},
(
error
)
=>
{
if
(
error
)
{
console
.
log
(
"
setIfaceConfig callback error =
"
+
error
);
}
else
{
console
.
log
(
"
setIfaceConfig callback ok
"
);
}
});
```
## ethernet.setIfaceConfig
...
...
@@ -74,10 +80,17 @@ setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise\<void>
**示例:**
```
js
ethernet
.
setIfaceConfig
(
"
eth0
"
,
{
mode
:
ethernet
.
STATIC
,
ipAddr
:
"
192.168.1.123
"
,
routeAddr
:
"
192.168.1.1
"
,
gateAddr
:
"
192.168.1.1
"
,
maskAddr
:
"
255.255.255.0
"
,
dnsAddr0
:
"
1.1.1.1
"
,
dnsAddr1
:
"
2.2.2.2
"
}).
then
(()
=>
{
ethernet
.
setIfaceConfig
(
"
eth0
"
,
{
mode
:
0
,
ipAddr
:
"
192.168.1.123
"
,
route
:
"
192.168.1.1
"
,
gateway
:
"
192.168.1.1
"
,
netMask
:
"
255.255.255.0
"
,
dnsServers
:
"
1.1.1.1
"
,
domain
:
"
2.2.2.2
"
}).
then
(()
=>
{
console
.
log
(
"
setIfaceConfig promiss ok
"
);
}).
catch
(
(
error
)
=>
{
}).
catch
(
error
=>
{
console
.
log
(
"
setIfaceConfig promiss error =
"
+
error
);
});
```
...
...
@@ -110,11 +123,11 @@ ethernet.getIfaceConfig("eth0", (error, value) => {
}
else
{
console
.
log
(
"
getIfaceConfig callback mode =
"
+
value
.
mode
);
console
.
log
(
"
getIfaceConfig callback ipAddr =
"
+
value
.
ipAddr
);
console
.
log
(
"
getIfaceConfig callback route
Addr =
"
+
value
.
routeAddr
);
console
.
log
(
"
getIfaceConfig callback gate
Addr =
"
+
value
.
gateAddr
);
console
.
log
(
"
getIfaceConfig callback
maskAddr =
"
+
value
.
maskAddr
);
console
.
log
(
"
getIfaceConfig callback dns
0Addr =
"
+
value
.
dns0Addr
);
console
.
log
(
"
getIfaceConfig callback d
ns1Addr =
"
+
value
.
dns1Addr
);
console
.
log
(
"
getIfaceConfig callback route
=
"
+
value
.
route
);
console
.
log
(
"
getIfaceConfig callback gate
way =
"
+
value
.
gateway
);
console
.
log
(
"
getIfaceConfig callback
netMask =
"
+
value
.
netMask
);
console
.
log
(
"
getIfaceConfig callback dns
Servers =
"
+
value
.
dnsServers
);
console
.
log
(
"
getIfaceConfig callback d
omain =
"
+
value
.
domain
);
}
});
```
...
...
@@ -149,12 +162,12 @@ getIfaceConfig(iface: string): Promise\<InterfaceConfiguration>
ethernet
.
getIfaceConfig
(
"
eth0
"
).
then
((
data
)
=>
{
console
.
log
(
"
getIfaceConfig promiss mode =
"
+
data
.
mode
);
console
.
log
(
"
getIfaceConfig promiss ipAddr =
"
+
data
.
ipAddr
);
console
.
log
(
"
getIfaceConfig promiss route
Addr =
"
+
data
.
routeAddr
);
console
.
log
(
"
getIfaceConfig promiss gate
Addr =
"
+
data
.
gateAddr
);
console
.
log
(
"
getIfaceConfig promiss
maskAddr =
"
+
data
.
maskAddr
);
console
.
log
(
"
getIfaceConfig promiss dns
0Addr =
"
+
data
.
dns0Addr
);
console
.
log
(
"
getIfaceConfig promiss d
ns1Addr =
"
+
data
.
dns1Addr
);
}).
catch
(
(
error
)
=>
{
console
.
log
(
"
getIfaceConfig promiss route
=
"
+
data
.
route
);
console
.
log
(
"
getIfaceConfig promiss gate
way =
"
+
data
.
gateway
);
console
.
log
(
"
getIfaceConfig promiss
netMask =
"
+
data
.
netMask
);
console
.
log
(
"
getIfaceConfig promiss dns
Servers =
"
+
data
.
dnsServers
);
console
.
log
(
"
getIfaceConfig promiss d
omain =
"
+
data
.
domain
);
}).
catch
(
error
=>
{
console
.
log
(
"
getIfaceConfig promiss error =
"
+
error
);
});
```
...
...
@@ -182,11 +195,11 @@ isIfaceActive(iface: string, callback: AsyncCallback\<number>): void
```
js
ethernet
.
isIfaceActive
(
"
eth0
"
,
(
error
,
value
)
=>
{
if
(
error
)
{
console
.
log
(
"
whether2Activate callback error =
"
+
error
);
}
else
{
console
.
log
(
"
whether2Activate callback =
"
+
value
);
}
if
(
error
)
{
console
.
log
(
"
whether2Activate callback error =
"
+
error
);
}
else
{
console
.
log
(
"
whether2Activate callback =
"
+
value
);
}
});
```
...
...
@@ -218,9 +231,9 @@ isIfaceActive(iface: string): Promise\<number>
```
js
ethernet
.
isIfaceActive
(
"
eth0
"
).
then
((
data
)
=>
{
console
.
log
(
"
isIfaceActive promiss =
"
+
data
);
}).
catch
(
(
error
)
=>
{
console
.
log
(
"
isIfaceActive promiss error =
"
+
error
);
console
.
log
(
"
isIfaceActive promiss =
"
+
data
);
}).
catch
(
error
=>
{
console
.
log
(
"
isIfaceActive promiss error =
"
+
error
);
});
```
...
...
@@ -246,14 +259,14 @@ getAllActiveIfaces(callback: AsyncCallback\<Array\<string>>): void
```
js
ethernet
.
getAllActiveIfaces
((
error
,
value
)
=>
{
if
(
error
)
{
console
.
log
(
"
getAllActiveIfaces callback error =
"
+
error
);
}
else
{
console
.
log
(
"
getAllActiveIfaces callback value.length =
"
+
value
.
length
);
for
(
let
i
=
0
;
i
<
value
.
length
;
i
++
)
{
console
.
log
(
"
getAllActiveIfaces callback =
"
+
value
[
i
]);
if
(
error
)
{
console
.
log
(
"
getAllActiveIfaces callback error =
"
+
error
);
}
else
{
console
.
log
(
"
getAllActiveIfaces callback value.length =
"
+
value
.
length
);
for
(
let
i
=
0
;
i
<
value
.
length
;
i
++
)
{
console
.
log
(
"
getAllActiveIfaces callback =
"
+
value
[
i
]);
}
}
}
});
```
...
...
@@ -280,11 +293,11 @@ getAllActiveIfaces(): Promise\<Array\<string>>
```
js
ethernet
.
getAllActiveIfaces
().
then
((
data
)
=>
{
console
.
log
(
"
getAllActiveIfaces promiss data.length =
"
+
data
.
length
);
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
log
(
"
getAllActiveIfaces promiss =
"
+
data
[
i
]);
}
}).
catch
(
(
error
)
=>
{
console
.
log
(
"
getAllActiveIfaces promiss error =
"
+
error
);
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
log
(
"
getAllActiveIfaces promiss =
"
+
data
[
i
]);
}
}).
catch
(
error
=>
{
console
.
log
(
"
getAllActiveIfaces promiss error =
"
+
error
);
});
```
...
...
zh-cn/application-dev/reference/apis/js-apis-net-sharing.md
浏览文件 @
10d8e2f8
...
...
@@ -145,7 +145,7 @@ startSharing(type: SharingIfaceType, callback: AsyncCallback\<void>): void
```
js
import
SharingIfaceType
from
'
@ohos.net.sharing
'
sharing
.
startSharing
(
SharingIfaceType
.
SHARING_WIFI
,
(
error
)
=>
{
sharing
.
startSharing
(
0
,
(
error
)
=>
{
console
.
log
(
JSON
.
stringify
(
error
));
});
```
...
...
@@ -178,7 +178,7 @@ startSharing(type: SharingIfaceType): Promise\<void>
```
js
import
SharingIfaceType
from
'
@ohos.net.sharing
'
sharing
.
startSharing
(
SharingIfaceType
.
SHARING_WIFI
).
then
(()
=>
{
sharing
.
startSharing
(
0
).
then
(()
=>
{
console
.
log
(
"
start wifi sharing successful
"
);
}).
catch
(
error
=>
{
console
.
log
(
"
start wifi sharing failed
"
);
...
...
@@ -208,7 +208,7 @@ stopSharing(type: SharingIfaceType, callback: AsyncCallback\<void>): void
```
js
import
SharingIfaceType
from
'
@ohos.net.sharing
'
sharing
.
stopSharing
(
SharingIfaceType
.
SHARING_WIFI
,
(
error
)
=>
{
sharing
.
stopSharing
(
0
,
(
error
)
=>
{
console
.
log
(
JSON
.
stringify
(
error
));
});
```
...
...
@@ -241,7 +241,7 @@ stopSharing(type: SharingIfaceType): Promise\<void>
```
js
import
SharingIfaceType
from
'
@ohos.net.sharing
'
sharing
.
stopSharing
(
SharingIfaceType
.
SHARING_WIFI
).
then
(()
=>
{
sharing
.
stopSharing
(
0
).
then
(()
=>
{
console
.
log
(
"
stop wifi sharing successful
"
);
}).
catch
(
error
=>
{
console
.
log
(
"
stop wifi sharing failed
"
);
...
...
@@ -436,7 +436,7 @@ getSharingIfaces(state: SharingIfaceState, callback: AsyncCallback\<Array\<strin
```
js
import
SharingIfaceState
from
'
@ohos.net.sharing
'
sharing
.
getSharingIfaces
(
SharingIfaceState
.
SHARING_NIC_CAN_SERVER
,
(
error
,
data
)
=>
{
sharing
.
getSharingIfaces
(
2
,
(
error
,
data
)
=>
{
console
.
log
(
JSON
.
stringify
(
error
));
console
.
log
(
JSON
.
stringify
(
data
));
});
...
...
@@ -470,7 +470,7 @@ getSharingIfaces(state: SharingIfaceState): Promise\<Array\<string>>
```
js
import
SharingIfaceState
from
'
@ohos.net.sharing
'
sharing
.
getSharingIfaces
(
SharingIfaceState
.
SHARING_NIC_CAN_SERVER
).
then
(
data
=>
{
sharing
.
getSharingIfaces
(
2
).
then
(
data
=>
{
console
.
log
(
JSON
.
stringify
(
data
));
}).
catch
(
error
=>
{
console
.
log
(
JSON
.
stringify
(
error
));
...
...
@@ -500,7 +500,7 @@ getSharingState(type: SharingIfaceType, callback: AsyncCallback\<SharingIfaceSta
```
js
import
SharingIfaceType
from
'
@ohos.net.sharing
'
sharing
.
getSharingState
(
SharingIfaceType
.
SHARING_WIFI
,
(
error
,
data
)
=>
{
sharing
.
getSharingState
(
0
,
(
error
,
data
)
=>
{
console
.
log
(
JSON
.
stringify
(
error
));
console
.
log
(
JSON
.
stringify
(
data
));
});
...
...
@@ -534,7 +534,7 @@ getSharingState(type: SharingIfaceType): Promise\<SharingIfaceState>
```
js
import
SharingIfaceType
from
'
@ohos.net.sharing
'
sharing
.
getSharingState
(
SharingIfaceType
.
SHARING_WIFI
).
then
(
data
=>
{
sharing
.
getSharingState
(
0
).
then
(
data
=>
{
console
.
log
(
JSON
.
stringify
(
data
));
}).
catch
(
error
=>
{
console
.
log
(
JSON
.
stringify
(
error
));
...
...
@@ -564,7 +564,7 @@ getSharableRegexes(type: SharingIfaceType, callback: AsyncCallback\<Array\<strin
```
js
import
SharingIfaceType
from
'
@ohos.net.sharing
'
sharing
.
getSharableRegexes
(
SharingIfaceType
.
SHARING_WIFI
,
(
error
,
data
)
=>
{
sharing
.
getSharableRegexes
(
0
,
(
error
,
data
)
=>
{
console
.
log
(
JSON
.
stringify
(
error
));
console
.
log
(
JSON
.
stringify
(
data
));
});
...
...
@@ -598,7 +598,7 @@ getSharableRegexes(type: SharingIfaceType): Promise\<Array\<string>>
```
js
import
SharingIfaceType
from
'
@ohos.net.sharing
'
sharing
.
getSharableRegexes
(
SharingIfaceType
.
SHARING_WIFI
).
then
(
data
=>
{
sharing
.
getSharableRegexes
(
0
).
then
(
data
=>
{
console
.
log
(
JSON
.
stringify
(
data
));
}).
catch
(
error
=>
{
console
.
log
(
JSON
.
stringify
(
error
));
...
...
@@ -627,9 +627,8 @@ on(type: 'sharingStateChange', callback: Callback\<boolean>): void
**示例:**
```
js
sharing
.
on
(
'
sharingStateChange
'
,
(
error
,
data
)
=>
{
console
.
log
(
JSON
.
stringify
(
error
));
console
.
log
(
JSON
.
stringify
(
data
));
sharing
.
on
(
'
sharingStateChange
'
,
(
data
)
=>
{
console
.
log
(
'
on sharingStateChange:
'
+
JSON
.
stringify
(
data
));
});
```
...
...
@@ -655,8 +654,7 @@ off(type: 'sharingStateChange', callback?: Callback\<boolean>): void
**示例:**
```
js
sharing
.
off
(
'
sharingStateChange
'
,
(
error
,
data
)
=>
{
console
.
log
(
JSON
.
stringify
(
error
));
sharing
.
off
(
'
sharingStateChange
'
,
(
data
)
=>
{
console
.
log
(
JSON
.
stringify
(
data
));
});
```
...
...
@@ -683,9 +681,8 @@ on(type: 'interfaceSharingStateChange', callback: Callback\<{ type: SharingIface
**示例:**
```
js
sharing
.
on
(
'
interfaceSharingStateChange
'
,
(
error
,
data
)
=>
{
console
.
log
(
JSON
.
stringify
(
error
));
console
.
log
(
JSON
.
stringify
(
data
));
sharing
.
on
(
'
interfaceSharingStateChange
'
,
(
data
)
=>
{
console
.
log
(
'
on interfaceSharingStateChange:
'
+
JSON
.
stringify
(
data
));
});
```
...
...
@@ -711,8 +708,7 @@ off(type: 'interfaceSharingStateChange', callback?: Callback\<{ type: SharingIfa
**示例:**
```
js
sharing
.
off
(
'
interfaceSharingStateChange
'
,
(
error
,
data
)
=>
{
console
.
log
(
JSON
.
stringify
(
error
));
sharing
.
off
(
'
interfaceSharingStateChange
'
,
(
data
)
=>
{
console
.
log
(
JSON
.
stringify
(
data
));
});
```
...
...
@@ -739,9 +735,8 @@ on(type: 'sharingUpstreamChange', callback: Callback\<NetHandle>): void
**示例:**
```
js
sharing
.
on
(
'
sharingUpstreamChange
'
,
(
error
,
data
)
=>
{
console
.
log
(
JSON
.
stringify
(
error
));
console
.
log
(
JSON
.
stringify
(
data
));
sharing
.
on
(
'
sharingUpstreamChange
'
,
(
data
)
=>
{
console
.
log
(
'
on sharingUpstreamChange:
'
+
JSON
.
stringify
(
data
));
});
```
...
...
@@ -767,8 +762,7 @@ off(type: 'sharingUpstreamChange', callback?: Callback\<NetHandle>): void
**示例:**
```
js
sharing
.
off
(
'
sharingUpstreamChange
'
,
(
error
,
data
)
=>
{
console
.
log
(
JSON
.
stringify
(
error
));
sharing
.
off
(
'
sharingUpstreamChange
'
,
(
data
)
=>
{
console
.
log
(
JSON
.
stringify
(
data
));
});
```
...
...
zh-cn/application-dev/reference/apis/js-apis-socket.md
浏览文件 @
10d8e2f8
...
...
@@ -1783,7 +1783,7 @@ connect(options: TLSConnectOptions, callback: AsyncCallback\<void>): void
```
js
let
tlsTwoWay
=
socket
.
constructTLSSocketInstance
();
// Two way authentication
tlsTwoWay
.
bind
({
address
:
'
192.168.xxx.xxx
'
,
port
:
xxxx
,
family
:
1
},
err
=>
{
tlsTwoWay
.
bind
({
address
:
'
192.168.xxx.xxx
'
,
port
:
8080
,
family
:
1
},
err
=>
{
if
(
err
)
{
console
.
log
(
'
bind fail
'
);
return
;
...
...
@@ -1794,7 +1794,7 @@ let options = {
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
192.168.xx.xxx
"
,
port
:
xxxx
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
...
...
@@ -1809,12 +1809,12 @@ let options = {
},
};
tlsTwoWay
.
connect
(
options
,
(
err
,
data
)
=>
{
console
.
error
(
err
);
console
.
log
(
data
);
console
.
error
(
"
connect callback error
"
+
err
);
console
.
log
(
JSON
.
stringify
(
data
)
);
});
let
tlsOneWay
=
socket
.
constructTLSSocketInstance
();
// One way authentication
tlsOneWay
.
bind
({
address
:
'
192.168.xxx.xxx
'
,
port
:
xxxx
,
family
:
1
},
err
=>
{
tlsOneWay
.
bind
({
address
:
'
192.168.xxx.xxx
'
,
port
:
8080
,
family
:
1
},
err
=>
{
if
(
err
)
{
console
.
log
(
'
bind fail
'
);
return
;
...
...
@@ -1824,7 +1824,7 @@ tlsOneWay.bind({address: '192.168.xxx.xxx', port: xxxx, family: 1}, err => {
let
oneWayOptions
=
{
address
:
{
address
:
"
192.168.xxx.xxx
"
,
port
:
xxxx
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
...
...
@@ -1833,8 +1833,8 @@ let oneWayOptions = {
},
};
tlsOneWay
.
connect
(
oneWayOptions
,
(
err
,
data
)
=>
{
console
.
error
(
err
);
console
.
log
(
data
);
console
.
error
(
"
connect callback error
"
+
err
);
console
.
log
(
JSON
.
stringify
(
data
)
);
});
```
...
...
@@ -1883,7 +1883,7 @@ connect(options: TLSConnectOptions): Promise\<void>
```
js
let
tlsTwoWay
=
socket
.
constructTLSSocketInstance
();
// Two way authentication
tlsTwoWay
.
bind
({
address
:
'
192.168.xxx.xxx
'
,
port
:
xxxx
,
family
:
1
},
err
=>
{
tlsTwoWay
.
bind
({
address
:
'
192.168.xxx.xxx
'
,
port
:
8080
,
family
:
1
},
err
=>
{
if
(
err
)
{
console
.
log
(
'
bind fail
'
);
return
;
...
...
@@ -1894,7 +1894,7 @@ let options = {
ALPNProtocols
:
[
"
spdy/1
"
,
"
http/1.1
"
],
address
:
{
address
:
"
xxxx
"
,
port
:
xxxx
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
...
...
@@ -1909,13 +1909,13 @@ let options = {
},
};
tlsTwoWay
.
connect
(
options
).
then
(
data
=>
{
console
.
log
(
data
);
console
.
log
(
JSON
.
stringify
(
data
)
);
}).
catch
(
err
=>
{
console
.
error
(
err
);
});
let
tlsOneWay
=
socket
.
constructTLSSocketInstance
();
// One way authentication
tlsOneWay
.
bind
({
address
:
'
192.168.xxx.xxx
'
,
port
:
xxxx
,
family
:
1
},
err
=>
{
tlsOneWay
.
bind
({
address
:
'
192.168.xxx.xxx
'
,
port
:
8080
,
family
:
1
},
err
=>
{
if
(
err
)
{
console
.
log
(
'
bind fail
'
);
return
;
...
...
@@ -1925,7 +1925,7 @@ tlsOneWay.bind({address: '192.168.xxx.xxx', port: xxxx, family: 1}, err => {
let
oneWayOptions
=
{
address
:
{
address
:
"
192.168.xxx.xxx
"
,
port
:
xxxx
,
port
:
8080
,
family
:
1
,
},
secureOptions
:
{
...
...
@@ -1934,7 +1934,7 @@ let oneWayOptions = {
},
};
tlsOneWay
.
connect
(
oneWayOptions
).
then
(
data
=>
{
console
.
log
(
data
);
console
.
log
(
JSON
.
stringify
(
data
)
);
}).
catch
(
err
=>
{
console
.
error
(
err
);
});
...
...
@@ -2263,7 +2263,7 @@ getCipherSuite(): Promise\<Array\<string>>
```
js
tls
.
getCipherSuite
().
then
(
data
=>
{
console
.
log
(
data
);
console
.
log
(
'
getCipherSuite success:
'
+
JSON
.
stringify
(
data
)
);
}).
catch
(
err
=>
{
console
.
error
(
err
);
});
...
...
@@ -2327,7 +2327,7 @@ getSignatureAlgorithms(): Promise\<Array\<string>>
```
js
tls
.
getSignatureAlgorithms
().
then
(
data
=>
{
console
.
log
(
data
);
console
.
log
(
"
getSignatureAlgorithms success
"
+
data
);
}).
catch
(
err
=>
{
console
.
error
(
err
);
});
...
...
@@ -2528,4 +2528,4 @@ TLS通信的协议版本。
| 类型 | 说明 |
| --------------------------------------------------------------------- | --------------------- |
|
[
cryptoFramework.EncodingBlob
](
js-apis-cryptoFramework.md#EncodingBlob
)
| 存储证书的数据和编码格式 |
\ No newline at end of file
|
[
cryptoFramework.EncodingBlob
](
js-apis-cryptoFramework.md#datablob
)
| 存储证书的数据和编码格式 |
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录