MCPcopy Index your code
hub / github.com/github/copilot-sdk / connectViaTcp

Method connectViaTcp

nodejs/src/client.ts:2466–2498  ·  view source on GitHub ↗

* Connect to the CLI server via TCP socket

()

Source from the content-addressed store, hash-verified

2464 * Connect to the CLI server via TCP socket
2465 */
2466 private async connectViaTcp(): Promise<void> {
2467 if (!this.runtimePort) {
2468 throw new Error("Server port not available");
2469 }
2470
2471 return new Promise((resolve, reject) => {
2472 this.socket = new Socket();
2473
2474 const connectionTimeout = setTimeout(() => {
2475 this.socket?.destroy();
2476 reject(new Error("Timeout connecting to CLI server"));
2477 }, 10000);
2478
2479 this.socket.connect(this.runtimePort!, this.actualHost, () => {
2480 clearTimeout(connectionTimeout);
2481 // Create JSON-RPC connection
2482 this.messageWriter = new TeardownResilientStreamMessageWriter(this.socket!);
2483 this.connection = createMessageConnection(
2484 new StreamMessageReader(this.socket!),
2485 this.messageWriter
2486 );
2487
2488 this.attachConnectionHandlers();
2489 this.connection.listen();
2490 resolve();
2491 });
2492
2493 this.socket.on("error", (error) => {
2494 clearTimeout(connectionTimeout);
2495 reject(new Error(`Failed to connect to CLI server: ${error.message}`));
2496 });
2497 });
2498 }
2499
2500 private attachConnectionHandlers(): void {
2501 if (!this.connection) {

Callers 1

connectToServerMethod · 0.95

Calls 3

connectMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected