![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
react-native-tcp-socket
Advanced tools
React Native TCP socket API for Android & iOS. It allows you to create TCP clients and servers sockets, simulating node's net API.
Working features
Install the library using either Yarn:
yarn add react-native-tcp-socket
or npm:
npm install --save react-native-tcp-socket
Linking the package manually is not required anymore with Autolinking.
iOS Platform:
$ cd ios && pod install && cd ..
# CocoaPods on iOS needs this extra step
Android Platform:
Modify your android/build.gradle configuration to match minSdkVersion = 21
:
buildscript {
ext {
...
minSdkVersion = 23
...
}
Modify your android/app/src/main/AndroidManifest.xml and add the following:
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
You then need to link the native parts of the library for the platforms you are using. The easiest way to link the library is using the CLI tool by running this command from the root of your project:
$ react-native link react-native-tcp-socket
If you can't or don't want to use the CLI tool, you can also manually link the library using the instructions below (click on the arrow to show them):
Libraries
➜ Add Files to [your project's name]
node_modules
➜ react-native-tcp-socket
and add TcpSocket.xcodeproj
libTcpSocket.a
to your project's Build Phases
➜ Link Binary With Libraries
Cmd+R
)<android/app/src/main/java/[...]/MainApplication.java
import com.reactlibrary.TcpSocketPackage;
to the imports at the top of the filenew TcpSocketPackage()
to the list returned by the getPackages()
methodandroid/settings.gradle
:
include ':react-native-tcp-socket'
project(':react-native-tcp-socket').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-tcp-socket/android')
android/app/build.gradle
:
compile project(':react-native-tcp-socket')
Import the library:
import TcpSocket from 'react-native-tcp-socket';
// var net = require('react-native-tcp-socket');
// Create socket
var client = TcpSocket.createConnection(options);
client.on('data', function(data) {
console.log('message was received', data);
});
client.on('error', function(error) {
console.log(error);
});
client.on('close', function(){
console.log('Connection closed!');
});
// Write on the socket
client.write("Hello server!");
// Close socket
client.destroy();
// NOT IMPLEMENTED IN ANDROID
var server = net.createServer(function(socket) {
socket.write('excellent!');
}).listen(12345);
createConnection()
Creates a TCP connection using the given options
.
options
Required. Available options for creating a socket. It is an object
with the following properties:
Property | Type | Description |
---|---|---|
host | String | Required. A valid server IP address in IPv4 format or "localhost" . |
port | Number | Required. A valid server port. |
[localAddress] | String | A valid local IP address to bind the socket. If not specified, the OS will decide. |
[localPort] | Number | A valid local port to bind the socket. If not specified, the OS will decide. |
[interface] | String | The interface to bind the socket. If not specified, it will use the current active connection. The current options are: "wifi" |
Looking for maintainers!
PR's welcome!
The library is released under the MIT license. For more information see LICENSE
.
FAQs
React Native TCP socket API for Android & iOS with SSL/TLS support
The npm package react-native-tcp-socket receives a total of 10,630 weekly downloads. As such, react-native-tcp-socket popularity was classified as popular.
We found that react-native-tcp-socket demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.