TCP/IP connection to server

Hi Community !

For one of my project using Ionic 2, I’ve to connect to a server using TCP/IP protocol.
Such as if I use Netcat to connect to host:post to send and receive messages.

I’ve read the documentation but I think there’s no module do to it ? I’ve anyone an idea how I can proceed ?

Thank in advance for your help !


You can try with cordova chrome tcp plugin but I don’t know if it works also in ionic2, see my example here:

Thank you for your reply !
I’ve already see your exemple but problem is that I don’t know how to load the plugin with Ionic 2, app return undefined error when I try to use it…

I don’t use ionic2 yet, but try to post your code so we can check…

I’ll do it as soon as possible !

I’ve also try with, I can connect and send a message but I think that events onData, onError, onClose are never fired…He’s maybe no more updated !


checkout TCP sockets in ionic

And if you want to debug, use adb logcat or use chrome DevTools to link to your device (Android I use) to see the logs and any other complaints the plugin gives


Thanks a lot ! I can now use it, connect to TCP server and send a message but I’m getting a time out, there’s no return data…
It’s maybe a problem with the server !

I tried to use the same code but it return Runtime error ( can’t find property ‘sockets’ of undefined). please help me


can you share the code you use to call?



import { Injectable } from ‘@angular/core’;
import { Http } from ‘@angular/http’;
import ‘rxjs/add/operator/map’;

export class TcpServicesProvider {

constructor(public http: Http) {
	console.log('Hello TcpServicesProvider Provider');

arrayBuffer2str(buf) {
	var str= '';
	var ui8= new Uint8Array(buf);
	for (var i= 0 ; i < ui8.length ; i++) {
		str= str+String.fromCharCode(ui8[i]);
	return str;

str2arrayBuffer(str) {
	var buf= new ArrayBuffer(str.length);
	var bufView= new Uint8Array(buf);
	for (var i= 0 ; i < str.length ; i++) {
		bufView[i]= str.charCodeAt(i);
	return buf;

sendPacket(ipAddr,ipPort,data) {
	console.log("from TcpServicesProvider")
	var delay= 5000;	/// 5 seconds timeout
	(<any>window).chrome.sockets.tcp.create({}, createInfo => { //callback function with createInfo as the parameter
		var _socketTcpId= createInfo.socketId;
		(<any>window).chrome.sockets.tcp.connect(_socketTcpId, ipAddr, ipPort, result => { //callback function with result as the parameter
			if (result === 0) {
				var data2send= this.str2arrayBuffer(data);
				/// connection ok, send the packet
				(<any>window).chrome.sockets.tcp.send(_socketTcpId, data2send);
		(<any>window).chrome.sockets.tcp.onReceive.addListener( info => { //callback function with info as the parameter
			/// recived, then close connection
			var data= this.arrayBuffer2str(;
		/// set the timeout
		setTimeout(function() {
		}, delay);


1 Like

This is the code I tried to use TCP sockets in ionic
but it returned error (can’t find property ‘sockets’ of undefined). I used “npm install cordova-plugin-chrome-apps-sockets-tcp --save”. but i still don’t know how to work with this plugin.


look at the code

Using “cordova-plugin-chrome-apps-sockets-tcp” “~1.3.7”

A bit different approach.



Is it working with you, @Tommertom ?

Sorry, it has been a while since I worked on it. No chance for testing the coming period.

Ok, I will try testing it again.