Skip to main content
Version: v6

WebSocket Server

This plugin allows you to run a single, lightweight, barebone WebSocket Server.

https://github.com/becvert/cordova-plugin-websocket-server

Stuck on a Cordova issue?

Don't waste precious time on plugin issues.

If you're building a serious project, you can't afford to spend hours troubleshooting. Ionic’s experts offer premium advisory services for both community plugins and premier plugins.

Installation

$ npm install cordova-plugin-websocket-server 
$ npm install @awesome-cordova-plugins/web-socket-server
$ ionic cap sync

Supported Platforms

  • Android
  • iOS

Usage

React

Learn more about using Ionic Native components in React

Angular

import { WebSocketServer } from '@awesome-cordova-plugins/web-socket-server';

constructor(private wsserver: WebSocketServer) { }

...

// start websocket server
this.wsserver.start(8888, {}).subscribe({
next: server => console.log(`Listening on ${server.addr}:${server.port}`),
error: error => console.log(`Unexpected error`, error);
});

// watch for any messages
this.wsserver.watchMessage().subscribe(result => {
console.log(`Received message ${result.msg} from ${result.conn.uuid}`);
});

// send message to connection with specified uuid
this.wsserver.send({ uuid: '8e7c4f48-de68-4b6f-8fca-1067a353968d' }, 'Hello World');

// stop websocket server
this.wsserver.stop().then(server => {
console.log(`Stop listening on ${server.addr}:${server.port}`);
});