npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@voicenter-team/tcp-transfer

v0.0.9

Published

A Node.js module for reliable TCP file transfer between client and server with support for failover connections, streaming, and robust error handling.

Downloads

14

Readme

TCP File Transfer

A Node.js module for reliable TCP file transfer between client and server with support for failover connections, streaming, and robust error handling.

Features

  • TCP-based file transfer client and server
  • Support for failover connections with multiple server endpoints
  • File streaming support with Transform streams
  • Connection retry mechanism with configurable attempts
  • Event-based progress monitoring and error handling
  • Temporary file handling
  • Configurable timeouts and connection limits
  • Protocol versioning and checksum validation
  • Support for both file and stream transfers

Installation

npm install @voicenter-team/tcp-transfer

Usage

Starting a Server

const NetFile = require('@voicenter-team/tcp-transfer');
const netFile = new NetFile();

const startServer = async () => {
  // Create server instance
  const server = new netFile.Server({
    port: 4000,
    maxConnections: 5,
    timeout: 20000,
    tempDir: './temp'
  });

  // Handle server events
  server.on(NetFile.ServerEvents.SERVER_STARTED, (info) => {
    console.log(`Server started on port ${info.port}`);
  });

  server.on(NetFile.ServerEvents.NEW_CONNECTION, (info) => {
    console.log(`New connection ${info.connectionId}`);
  });

  server.on(NetFile.ServerEvents.FILE_TRANSFERRED, (connection) => {
    console.log('File transferred:', connection.metadata);
    
    // Process the file and send response
    connection.send({
      type: 'processing_status',
      status: 'complete',
      receivedBytes: connection.receivedBytes,
      data: { result: 'success' }
    });
  });

  // Start the server
  await server.start();
}

Using the Client

const NetFile = require('@voicenter-team/tcp-transfer');
const netFile = new NetFile();
const fs = require('fs');
const path = require('path');

// File Transfer Example
const sendFile = async () => {
  try {
    const client = await netFile.failoverClient(
      ['tcp://localhost:4002', 'tcp://localhost:4000'],
      { connectionTimeOut: 3600000 } // 1 hour
    );

    client.on('info', (info) => console.log('Client info:', info));
    
    const response = await client.sendFile('./path/to/file.wav');
    console.log('Transfer response:', response);
  } catch (err) {
    console.error('Error:', err);
  }
};

// Stream Transfer Example
const streamTransfer = async () => {
  try {
    const client = await netFile.failoverClient(['tcp://localhost:4000']);
    const filePath = './path/to/file.wav';
    const fileStats = fs.statSync(filePath);
    const fileStream = fs.createReadStream(filePath);

    const response = await client.transfer(fileStream, {
      filename: path.basename(filePath),
      fileSize: fileStats.size,
      responseTimeOut: 6000
    });
    
    console.log('Stream transfer response:', response);
  } catch (err) {
    console.error('Error:', err);
  }
};

API Reference

Server Class

Constructor Options

{
  port: 4000,              // Server port number
  maxConnections: 5,       // Maximum concurrent connections
  timeout: 20000,          // Connection timeout in ms
  tempDir: './temp'        // Directory for temporary files
}

Events

  • SERVER_STARTED - Server started successfully
  • NEW_CONNECTION - New client connected
  • CONNECTION_CLOSED - Client disconnected
  • SERVER_ERROR - Server error occurred
  • FILE_TRANSFERRED - File transfer completed
  • CONNECTION_REJECTED - Connection rejected (max connections reached)

Client Class

Constructor Options

{
  connectionTimeOut: 10000,  // Connection timeout in ms
  timeoutAttempt: 2000,     // Retry attempt timeout in ms
  maxRetries: 3             // Maximum connection retries
}

Methods

  • connect() - Establish connection to server
  • sendFile(filePath, options) - Send a file
  • transfer(stream, options) - Transfer a stream
  • disconnect() - Close connection

Events

  • info - Transfer progress information
  • error - Error information
  • connection - Connection status
  • transfer - Transfer status
  • message - Server messages

Protocol Class

Handles message formatting, checksums, and versioning for reliable data transfer.

{
  maxLength: 32 * 1024 * 1024,  // Maximum message length (32MB)
  timeoutMs: 45000              // Message timeout (45 seconds)
}

Error Handling

The module includes comprehensive error handling for:

  • Connection failures
  • Transfer timeouts
  • Maximum connection limits
  • Protocol version mismatches
  • Checksum validation
  • Stream errors

License

MIT

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.