{"id":47321,"library":"cordova-plugin-websocket-server","title":"Cordova WebSocket Server Plugin","description":"A Cordova plugin that enables running a single, lightweight WebSocket server on Android and iOS devices. Version 1.6.0 is the latest release. It allows starting/stopping a server on a specified port, managing WebSocket connections (open, message, close events), and sending/receiving text and binary messages. The server is not a background service and stops when the Cordova view is destroyed. Key differentiators: simple callback-based API, built-in support for network interface enumeration, and origin/protocol validation. The plugin relies on platform-specific libraries: TooTallNate Java-WebSocket for Android and PocketSocket for iOS.","status":"active","version":"1.6.0","language":"javascript","source_language":"en","source_url":"https://github.com/becvert/cordova-plugin-websocket-server","tags":["javascript","ecosystem:cordova","cordova-android","cordova-ios","cordova","plugin","network","websocket","server"],"install":[{"cmd":"npm install cordova-plugin-websocket-server","lang":"bash","label":"npm"},{"cmd":"yarn add cordova-plugin-websocket-server","lang":"bash","label":"yarn"},{"cmd":"pnpm add cordova-plugin-websocket-server","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Plugin framework required for installation and usage","package":"cordova","optional":false}],"imports":[{"note":"This is a Cordova plugin, so it must be accessed via cordova.plugins after device ready. ES6 import does not work.","wrong":"import wsserver from 'cordova-plugin-websocket-server';","symbol":"wsserver","correct":"var wsserver = cordova.plugins.wsserver;"},{"note":"The start method takes a port number, an options object with event handlers, and success/failure callbacks.","symbol":"start","correct":"wsserver.start(port, options, successCallback, failureCallback);"},{"note":"Stops the server. The success callback receives the address and port that were stopped.","symbol":"stop","correct":"wsserver.stop(successCallback, failureCallback);"},{"note":"The first parameter must be an object with a 'uuid' property, not just the UUID string.","wrong":"wsserver.send(uuid, msg);","symbol":"send","correct":"wsserver.send(conn, msg);"}],"quickstart":{"code":"document.addEventListener('deviceready', function () {\n    var wsserver = cordova.plugins.wsserver;\n    wsserver.start(8080, {\n        onFailure: function(addr, port, reason) { console.log('Failure: ' + reason); },\n        onOpen: function(conn) { console.log('Connected: ' + conn.remoteAddr); },\n        onMessage: function(conn, msg) { console.log('Message: ' + msg); },\n        onClose: function(conn, code, reason, wasClean) { console.log('Disconnected'); }\n    }, function(addr, port) {\n        console.log('Server started on ' + addr + ':' + port);\n    }, function(reason) {\n        console.log('Failed to start: ' + reason);\n    });\n}, false);","lang":"javascript","description":"Demonstrates starting a WebSocket server on port 8080 after device ready, with event handlers for connection lifecycle."},"warnings":[{"fix":"Do not rely on the server persisting after app is backgrounded or terminated.","message":"Server stops when Cordova view is destroyed. Not a background service.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use wsserver.send({uuid: '...'}, msg) instead of wsserver.send('...', msg).","message":"First parameter to send() must be an object with uuid, not just a UUID string.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Pass a specific port number (e.g., 8080) instead of 0.","message":"wsserver.start port 0 does not bind to a random port; it binds to port 0 which is invalid on some platforms.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always provide at least a failure callback to catch errors.","message":"The success and failure callbacks in start() are optional but if omitted, errors are silent.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.6.0':22 'allow':28 'android':17,95,105 'api':70 'background':54 'base':69 'binari':47 'built':72 'built-in':71 'callback':68 'callback-bas':67 'close':41 'connect':38 'cordova':1,6,60,102,104,107,109 'cordova-android':103 'cordova-io':106 'destroy':63 'devic':20 'differenti':65 'ecosystem':101 'enabl':9 'enumer':78 'event':42 'interfac':77 'io':19,99,108 'java':92 'java-websocket':91 'javascript':100 'key':64 'latest':25 'librari':89 'lightweight':13 'manag':36 'messag':40,48 'network':76,111 'open':39 'origin/protocol':80 'platform':87 'platform-specif':86 'plugin':4,7,83,110 'pocketsocket':97 'port':35 'releas':26 'reli':84 'run':10 'sending/receiving':44 'server':3,15,31,50,113 'servic':55 'simpl':66 'singl':12 'specif':88 'specifi':34 'starting/stopping':29 'stop':57 'support':74 'text':45 'tootalln':90 'valid':81 'version':21 'view':61 'websocket':2,14,37,93,112","created_at":"2026-06-07T16:50:56.026764+00:00","updated_at":"2026-06-07T16:50:56.026764+00:00","problems":[{"fix":"Wrap code in 'deviceready' event listener or run on a real device/emulator.","cause":"Code executed before device ready event or outside Cordova environment.","error":"ReferenceError: cordova is not defined"},{"fix":"Ensure cordova.plugins.wsserver is available after deviceready. Check plugin installation.","cause":"Plugin not loaded or wsserver accessed incorrectly.","error":"TypeError: wsserver.send is not a function"},{"fix":"Choose an unused port (e.g., >1024) and verify network permissions in config.xml.","cause":"Port already in use or network permission missing.","error":"Error: start failed (websocket server could not bind to port)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/becvert/cordova-plugin-websocket-server","github":"https://github.com/becvert/cordova-plugin-websocket-server","docs":null,"changelog":null,"pypi":null,"npm":"cordova-plugin-websocket-server","openapi_spec":null,"status_page":null,"smithery":null,"categories":["messaging"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}