* 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)
| 353 | * @returns {Promise<import("@cloudflare/workers-types").Socket>} A Promise that resolves to the connected socket. |
| 354 | */ |
| 355 | async function connectAndWrite(address, port) { |
| 356 | /** @type {import("@cloudflare/workers-types").Socket} */ |
| 357 | const tcpSocket = connect({ |
| 358 | hostname: address, |
| 359 | port: port, |
| 360 | }); |
| 361 | remoteSocket.value = tcpSocket; |
| 362 | log(`connected to ${address}:${port}`); |
| 363 | const writer = tcpSocket.writable.getWriter(); |
| 364 | await writer.write(rawClientData); // first write, nomal is tls client hello |
| 365 | writer.releaseLock(); |
| 366 | return tcpSocket; |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * Retries connecting to the remote address and port if the Cloudflare socket has no incoming data. |
no test coverage detected