I have an ionic app that needs to make a TCP socket connection between it and a Wifi access point(no internet just a local access point).
The only library I could find for doing this from the client side was Chrome Sockets(Deprecated) and Chrome Sockets TCP
I was able to create the TCP socket, connect, send and receive with the deprecated version. But I always got the same string back in the response that I sent over the connection which was not the expected behavior.
When I moved to the supported Chrome Sockets TCP lib I could create the socket but not connect to it. I came across this CCA command line tool tutorial after seeing some Stack Overflow posts talking about a manifest.mobile.json
file which I did not have in my ionic app.
I installed the CCA command line tool and ran through the tutorial to create a basic CCA app. I grabbed the generated manifest.mobile.json
file from that and through it in the www
folder of mine and tried to connect again with no better results. Here is the generated manifest.mobile.json
file with a few lines I added based on ;
{
"packageId": "com.your.company.ChromeApp",
// Android-only overrides here (e.g. icons, name, version)
"android": {
},
// iOS-only overrides here (e.g. icons, name, version)
"ios": {
},
// Uncomment to use system WebView rather than Crosswalk
"webview": "system",
// Uncomment to enable use of eval()
"cspUnsafeEval": true,
// Uncomment to enable use of inline <script>
"cspUnsafeInline": true,
"sockets": {
"tcp": {"connect" : "*"}
}
}
And this is the code used to make and connect to the tcp socket
chrome.sockets.tcp.create(function(createInfo) {
chrome.sockets.tcp.connect(createInfo.socketId, 'MY_IP', MY_PORT, function(result) {
if (result === 0) {
chrome.sockets.tcp.send(createInfo.socketId, PID, function(result) {
if (result.resultCode === 0) {
console.log('connectAndSend: success');
chrome.sockets.tcp.disconnect(createInfo.socketId);
chrome.sockets.tcp.close(createInfo.socketId);
}
});
}
});
});
And the error message I get
failed to connect to /MY_IP (port MY_PORT): connect failed: ENETUNREACH (Network is unreachable)
callbackWithError @ errors.js:30
fail @ sockets.tcp.js:68
cordova.callbackFromNative @ cordova.js:293
processMessage @ cordova.js:1079
processMessages @ cordova.js:1102