Skip to main content

WebSocket Server

This plugin allows you to run a single, lightweight, barebone 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.


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

Supported Platforms#

  • Android
  • iOS



Learn more about using Ionic Native components in React


import { WebSocketServer } from '@ionic-native/web-socket-server';
constructor(private wsserver: WebSocketServer) { }
// start websocket serverthis.wsserver.start(8888, {}).subscribe({  next: server => console.log(`Listening on ${server.addr}:${server.port}`),  error: error => console.log(`Unexpected error`, error);});
// watch for any messagesthis.wsserver.watchMessage().subscribe(result => {  console.log(`Received message ${result.msg} from ${result.conn.uuid}`);});
// send message to connection with specified uuidthis.wsserver.send({ uuid: '8e7c4f48-de68-4b6f-8fca-1067a353968d' }, 'Hello World');
// stop websocket serverthis.wsserver.stop().then(server => {  console.log(`Stop listening on ${server.addr}:${server.port}`);});