Hello,
i wrote an easy TCP/IP Server in Python and a client in Javascript. if i start it in cmd on two computers it works perfect.
now i wanted to implement it in my Application. It should connect when i start the application. But I just get a white screen. I read already, it´s not possible to implement a net.Socket on websites, but how is it in ionic?
I just kept it easy now, but at the end i want to send some values from the server to the Application. So just backend stuff.
here is my code:
client:
var net = require('net');
var wert;
var client = new net.Socket();
client.connect(65432, '192.168.131.224', function() {
console.log('Connected');
});
client.on('data', function(data) {
console.log('Received: ' + data);
wert = data;
client.destroy(); // kill client after server's response
});
app.components.ts
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { ScreenOrientation } from '@ionic-native/screen-orientation';
import * as client from '../assets/data/client';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:string = 'HomePage';
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, public screenOrientation: ScreenOrientation) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);
client.connect();
client.on();
});
}
}