MCPcopy Create free account
hub / github.com/Ptechgithub/configs / connectAndWrite

Function connectAndWrite

worker.js:277–289  ·  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

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.

Callers 2

retryFunction · 0.85
handleTCPOutBoundFunction · 0.85

Calls 1

logFunction · 0.85

Tested by

no test coverage detected