You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since `react-native-tcp-socket` offers the same API as Node's net, in case you want to import this module as `net` or use `require('net')` in your JavaScript, you must add the following lines to your `package.json` file.
46
+
47
+
```json
48
+
{
49
+
"react-native": {
50
+
"net": "react-native-tcp-socket"
51
+
}
52
+
}
53
+
```
54
+
55
+
In addition, in order to obtain the TS types (or autocompletion) provided by this module, you must also add the following to your custom declarations file.
56
+
57
+
```ts
58
+
...
59
+
declaremodule'net' {
60
+
importTcpSocketsfrom'react-native-tcp-socket';
61
+
export=TcpSockets;
62
+
}
63
+
```
64
+
65
+
If you want to avoid duplicated `net` types, make sure not to use the default `node_modules/@types` in your `tsconfig.json``"typeRoots"` property.
66
+
67
+
_Check the [example app](./examples/tcpsockets/) provided for a working example._
68
+
69
+
43
70
#### Using React Native >= 0.60
44
71
Linking the package manually is not required anymore with [Autolinking](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md).
In this folder, you can find a variety of examples to help you get started in using `react-native-tcp-socket`. Every example has a specific purpose and **is compatible** with Node.js.
4
+
5
+
In order to run an example, you may import the `init`, `server` and clients from the example file and run it either from React Native ([`App.js`](../App.js)) or Node.js ([`main.js`](main.js)).
6
+
7
+
Let us know if you find any issues. If you want to contribute or add a new example, feel free to submit a PR!
8
+
9
+
## Table of Contents <!-- omit in toc -->
10
+
-[Echo server](#echo-server)
11
+
12
+
13
+
### [Echo server](echo.js)
14
+
15
+
An echo server just reflects a message received from a client to the same client. If we send a message saying "Hello, Server!", we will receive the same message, just like an echo. This example shows some basic TCP server and client interactions.
0 commit comments