I'm using Electron and I need to be able to send/receive from a server using tcp sockets. I have the client set up and I'm able to send to the server (I can confirm the server is receiving this lines).
However, I can't seem to figure out how to "listen/read" from the server when it replies back to me. This is the function I'm using to handle communication between my client and the socket server
var net = require('net');
function mySocket(message){
socketClient = net.connect({host: MY_IP, port: MY_PORT}, () => {
socketClient.setEncoding('utf8');
socketClient.write(message);
});
socketClient.on('data', (data) => {
alert(data);
});
socketClient.on('end', () => {
alert('Disconnected');
});
}
Running this function succesfully sends a message to the server:
"mySocket('Hello, its me)"
However the "reading" is not working. The server is sending the reply but my client is not able to read it in order to show it back to me.
What am I doing wrong?
Side note, the server is not a Node.JS server. It's a simple socket server done in, I belief, Pascal. I'm able to send/get replies from this same server using TCP sockets in Android, Java, Ruby, and many others so it should be able to work with Electron.