MCPcopy Index your code
hub / github.com/Ptechgithub/pp-worker / connectAndWrite

Function connectAndWrite

_worker.js:355–367  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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.

Callers 2

retryFunction · 0.85
handleTCPOutBoundFunction · 0.85

Calls 1

logFunction · 0.85

Tested by

no test coverage detected