* Connects to a given address and port and writes data to the socket. * @param {string} address The address to connect to. * @param {number} port The port to connect to. * @returns {Promise } A Promise that resolves to the connected socket.
(address, port)
| 275 | * @returns {Promise<import("@cloudflare/workers-types").Socket>} A Promise that resolves to the connected socket. |
| 276 | */ |
| 277 | async function connectAndWrite(address, port) { |
| 278 | /** @type {import("@cloudflare/workers-types").Socket} */ |
| 279 | const tcpSocket = connect({ |
| 280 | hostname: address, |
| 281 | port: port, |
| 282 | }); |
| 283 | remoteSocket.value = tcpSocket; |
| 284 | log(`connected to ${address}:${port}`); |
| 285 | const writer = tcpSocket.writable.getWriter(); |
| 286 | await writer.write(rawClientData); // first write, nomal is tls client hello |
| 287 | writer.releaseLock(); |
| 288 | return tcpSocket; |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Retries connecting to the remote address and port if the Cloudflare socket has no incoming data. |
no test coverage detected