GithubHelp home page GithubHelp logo

isabella232 / react-native-udp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from status-im/react-native-udp

0.0 0.0 0.0 247 KB

node's dgram for react-native

License: MIT License

JavaScript 3.45% Objective-C 84.32% Java 12.24%

react-native-udp's Introduction

UDP in React Native

node's dgram API in React Native

This module is used by Tradle

Install

npm install --save react-native-udp

Link in the native dependency

react-native link react-native-udp
# OR, if you're using react-native older than 0.31:
rnpm link react-native-udp

Android

  • Register and load the Native Module in your Main application (import, getPackages)
    • Note: prior to react-native 0.29.2, this should happen in your Main Activity
...

import com.tradle.react.UdpSocketsModule;			// <--- import //

public class MainApplication extends Application implements ReactApplication {
	...
	@Override
	protected List<ReactPackage> getPackages() {
		return Arrays.<ReactPackage>asList(
			new MainReactPackage(),
			new UdpSocketsModule()				// <- add here //
		);
	}
}

Buckle up, Dorothy

Usage

package.json

only if you want to write require('dgram') in your javascript

{
  "browser": {
    "dgram": "react-native-udp"
  }
}

JS

see/run index.js for a complete example, but basically it's just like dgram

var dgram = require('dgram')
// OR, if not shimming via package.json "browser" field:
// var dgram = require('react-native-udp')
var socket = dgram.createSocket('udp4')
socket.bind(12345)
socket.once('listening', function() {
  var buf = toByteArray('excellent!')
  socket.send(buf, 0, buf.length, remotePort, remoteHost, function(err) {
    if (err) throw err

    console.log('message was sent')
  })
})

socket.on('message', function(msg, rinfo) {
  console.log('message was received', msg)
})

Note

If you want to send and receive node Buffer objects, you'll have to "npm install buffer" and set it as a global for UdpSockets to pick it up:

global.Buffer = global.Buffer || require('buffer').Buffer

TODO

add select tests from node's tests for dgram

Contributors

Mark Vayngrib
Ellen Katsnelson
Tradle, Inc.

Andy Prock

PR's welcome!

react-native-udp's People

Contributors

aprock avatar atticoos avatar intmainvoid avatar jmc420 avatar marcusstenbeck avatar mvayngrib avatar syaau avatar the-ress avatar tohjg avatar yesmeck avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.