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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@yesprasoon/capacitor-tcp-socket-manager

v1.2.2

Published

A Capacitor plugin for Android to enable TCP socket server and client communication in hybrid mobile apps.

Readme

Capacitor TCP Socket Manager

capacitor-tcp-socket-manager is an Android-specific Capacitor plugin that enables seamless TCP socket communication for your hybrid mobile apps. It allows you to create a TCP server, manage client connections, send and receive messages, and handle various socket operations efficiently. Note: This plugin currently supports Android only.


npm npm downloads license

Table of Contents


Features

  • Start and stop a TCP server.
  • Connect to a TCP server as a client.
  • Send and receive messages.
  • Manage multiple client connections.
  • Get the local device's IP address.
  • Limit maximum client connections (default is 10).
  • Disconnect individual or all clients gracefully.

Installation

Prerequisites

  • Capacitor 4 or later
  • Android Studio installed and configured
  • Node.js and npm installed

Steps

  1. Install the plugin:

    For Capacitor 7:

    npm install @yesprasoon/capacitor-tcp-socket-manager

    For Capacitor 6:

    npm install @yesprasoon/capacitor-tcp-socket-manager@^1.1.2
  2. Sync with Capacitor:

    npx cap sync
  3. Rebuild the Android project:

    npx cap open android

API Methods

Server-Side Methods

startServer

Starts a TCP server on the specified port.

Parameters:

  • port: (optional, default: 8080) Port number to start the server on.

Returns:

  • ipAddress: The IP address of the server.
  • port: The port on which the server is running.

Usage:

TcpSocketManager.startServer({ port: 8080 })
  .then(response => console.log(`Server started on ${response.ipAddress}:${response.port}`))
  .catch(error => console.error(error));

stopServer

Stops the TCP server if running.

Usage:

TcpSocketManager.stopServer()
  .then(() => console.log('Server stopped'))
  .catch(error => console.error(error));

getClientCount

Gets the number of currently connected clients.

Returns:

  • count: The number of connected clients.

Usage:

TcpSocketManager.getClientCount()
  .then(result => console.log(`Connected clients: ${result.count}`))
  .catch(error => console.error(error));

Client-Side Methods

connectToServer

Connects to a TCP server.

Parameters:

  • ipAddress: The IP address of the server.
  • port: (optional, default: 8080) Port number of the server.

Usage:

TcpSocketManager.connectToServer({ ipAddress: '192.168.0.100', port: 8080 })
  .then(() => console.log('Connected to server'))
  .catch(error => console.error(error));

disconnectFromServer

Disconnects from the connected server.

Usage:

TcpSocketManager.disconnectFromServer()
  .then(() => console.log('Disconnected from server'))
  .catch(error => console.error(error));

sendMessageToServer

Sends a message to the connected server.

Parameters:

  • message: The message string to send.
  • ipAddress: (optional): The IP address of the server. If not provided, the stored IP address (from the connection step) will be used.
  • port: (optional, default: 8080): Port number of the server. If not provided, the stored port (from the connection step) will be used.

Usage:

TcpSocketManager.sendMessageToServer({ message: 'Hello Server!' })
  .then(() => console.log('Message sent successfully'))
  .catch(error => console.error('Failed to send message:', error));

Events

receiveMessage

Listens for incoming messages on the server.

Usage:

TcpSocketManager.addListener('receiveMessage', data => {
  console.log(`Message received: ${data.message}`);
});

Example Usage

Starting a Server

TcpSocketManager.startServer({ port: 8080 })
  .then(response => console.log(`Server is running on ${response.ipAddress}:${response.port}`))
  .catch(error => console.error(error));

Sending a Message from Client to Server

TcpSocketManager.connectToServer({ ipAddress: '192.168.0.100', port: 8080 })
  .then(() => {
    return TcpSocketManager.sendMessageToServer({ message: 'Hello, Server!' });
  })
  .then(() => console.log('Message sent to server'))
  .catch(error => console.error(error));

Planned Features

We are continuously improving this plugin. Future updates may include:

  • TLS/SSL communication for secure connections.
  • IP whitelisting for enhanced access control.
  • Client authentication mechanisms.
  • Message acknowledgment for reliable communication.
  • Automatic client reconnection.

All suggestions are welcome!


Troubleshooting

Problem: Server does not start

  • Ensure the port is not already in use by another application.
  • Check for sufficient permissions in your app's AndroidManifest.xml.

Problem: Unable to connect to the server

  • Verify the IP address and port are correct.
  • Ensure the device is on the same network as the server.

License

This project is licensed under the MIT License. See the LICENSE file for more details.