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

@onekeyfe/react-native-tcp-socket

v6.8.0-6

Published

react-native-tcp-socket

Readme

@onekeyfe/react-native-tcp-socket

One-shot TCP connection probes with a measured connect time.

npm license iOS Android TurboModule

Opens a TCP connection to a host and port, then closes it and resolves the elapsed connection time in milliseconds. A small createConnection compatibility shim is included for call sites written against the upstream react-native-tcp-socket API. This is a diagnostic probe, not a streaming socket: no data, write, end, TLS or socket handle is exposed. There is no Web implementation.

Features

  • One call, one measurement — connectWithTimeout(host, port, timeoutMs) resolves the connect time in milliseconds or rejects with the failure.
  • Bounded connect wait — the wait is cut off at timeoutMs and rejects instead of hanging the caller.
  • No retained connection — the socket is opened and closed inside the call; there is nothing to keep alive or dispose.
  • Compatibility shim — createConnection(options, callback) supports on('error'), on('timeout') and destroy() for simple call sites.
  • Typed native failures on iOS — DNS_ERROR, CONNECT_ERROR, ETIMEDOUT, SOCKET_ERROR and SELECT_ERROR distinguish the failure stage.

Installation

yarn add @onekeyfe/react-native-tcp-socket

Install the app's iOS pods and rebuild the native binary; Android links through autolinking. The application must declare the normal INTERNET permission:

<uses-permission android:name="android.permission.INTERNET" />

No additional iOS permission or entitlement is required.

Usage

import { NativeTcpSocket } from '@onekeyfe/react-native-tcp-socket';

// Resolves the time spent resolving and connecting, in milliseconds.
const connectMs = await NativeTcpSocket.connectWithTimeout('1.1.1.1', 443, 5000);

Keep the result associated with the host, port and network conditions of that call. Retry policy and the meaning of the measurement belong to the caller.

API

| Export | Signature | Platforms | Description | | --- | --- | :-: | --- | | NativeTcpSocket.connectWithTimeout | (host: string, port: number, timeoutMs: number) => Promise<number> | iOS, Android | Attempts one TCP connection and resolves its elapsed time in ms. | | default createConnection | (options: { host, port, timeout? }, connectCallback: () => void) => TcpSocketShim | iOS, Android | Compatibility shim over the promise API; default timeout 5000 ms. | | TcpSocketShim.on | (event, handler) => this with event error or timeout | iOS, Android | Registers the current error or timeout callback. | | TcpSocketShim.destroy | () => void | iOS, Android | Suppresses later shim callbacks; it does not cancel the native attempt. |

The TypeScript interface is in src/NativeTcpSocket.ts; the shim is in src/index.tsx.

Platform support

| Capability | iOS | Android | Web | | --- | :-: | :-: | :-: | | One-shot TCP connect probe | ✅ | ✅ | — | | Measured connect time in ms | ✅ | ✅ | — | | Connect timeout | ✅ select() deadline | ✅ Socket.connect timeout | — | | Streaming read/write API | — | — | — | | Native cancellation | — | — | — | | createConnection shim | ✅ | ✅ | — |

Caveats

[!IMPORTANT] This package is a connectivity diagnostic, not a socket implementation. A successful connect does not verify TLS, an application protocol or an authenticated service, and destroy() suppresses callbacks without cancelling the native attempt.

[!WARNING] On Android every native failure rejects with the single code TCP_SOCKET_ERROR. The shim classifies timeouts by message text, so Android connect timed out rejections arrive through the error handler rather than the timeout handler.

[!NOTE] timeoutMs bounds the connection wait only. DNS resolution happens before the timed wait on both platforms, and iOS attempts only the first address returned by getaddrinfo (over an IPv4 socket), so an IPv6-first host can reject with CONNECT_ERROR.

References

Upstream attribution

First, a sincere thank-you to Rapsssito and the react-native-tcp-socket maintainers for their excellent work 🙏

This package is built on, and inspired by, Rapsssito/react-native-tcp-socket.

Our original plan was to keep our customizations as patches on top of upstream react-native-tcp-socket.

As our product requirements evolved, the scope of those changes outgrew what we could reasonably maintain as an upstream patch set. We regret that we were unable to keep this work in patch form.

As the gap grew, we ultimately forked react-native-tcp-socket to keep development and delivery stable.

Upstream Project

Notes

  • This fork includes OneKey-specific adaptations for our product requirements.
  • If you are looking for original behavior and full documentation, please refer to the upstream repository.

Thank you again to Rapsssito and everyone who contributes to react-native-tcp-socket 💙

License

MIT. See LICENSE.