Deno.connect
connect
-
connect(options: ConnectOptions | UnixConnectOptions): Promise<Conn>
-
通过指定传输协议(默认 “tcp”)连接主机名(默认 “127.0.0.1”)和端口号,并异步返回这个连接(
Conn
)。Connects to the hostname (default is “127.0.0.1”) and port on the named transport (default is “tcp”), and resolves to the connection (
Conn
).const conn1 = await Deno.connect({ port: 80 }); const conn2 = await Deno.connect({ hostname: "192.0.2.1", port: 80 }); const conn3 = await Deno.connect({ hostname: "[2001:db8::1]", port: 80 }); const conn4 = await Deno.connect({ hostname: "golang.org", port: 80, transport: "tcp" }); const conn5 = await Deno.connect({ address: "/foo/bar.sock", transport: "unix" });
“tcp” 需要
allow-net
权限,unix 需要allow-read
权限。Requires
allow-net
permission for “tcp” andallow-read
for unix.
参数
- ##### options: [ConnectOptions](interfaces/deno.connectoptions.html) | [UnixConnectOptions](interfaces/deno.unixconnectoptions.html)