Saturday, 15 April 2017

How to create a TCP/IP echo server in Electron.js?

i'm trying to create a simple tcp/ip server in electron.js. I declare my server after

app.on('ready', function(){
    createWindow()
})

function something like that

const net = require('net')

net.createServer(function(sock) {
    console.log('Server has been started')
    console.log('Client connected: ' + sock.remoteAddress +':'+ sock.remotePort)

    sock.on('data', function(data) {

        console.log('DATA ' + sock.remoteAddress + ': ' + data)
        sock.write(data)
    });
    sock.on('close', function(data) {
        console.log('CLOSED: ' + sock.remoteAddress +' '+ sock.remotePort)
    });

}).listen(10003, 'localhost')

but when i try to connect to server nothing happens. What do i wrong?



via DWilde

No comments:

Post a Comment