React-Native-connect-server

Initial React Native

1
$ npx react-native init imapp && cd imapp

Run on ios

1
$ npx react-native-run-ios

Install SocketCluster Client

1
$ yarn add socketcluster-client

Initial Socket

App.js

1
2
3
4
5
6
7
8
import SocketClusterClient from 'socketcluster-client';

let socket = SocketClusterClient.create({
hostname: 'localhost',
port: 8000
});

socket.transmit('foo', 123);

Server 可以收到 data

基本上已經可以確認接通了 SocketCluster Server 與 Client

之後就可以準備其他事情

參考資料

socketcluster-Client

文章目录
  1. 1. Initial React Native
    1. 1.1. Run on ios
    2. 1.2. Install SocketCluster Client
    3. 1.3. Initial Socket
  2. 2. 參考資料
|