-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtcp.js
50 lines (33 loc) · 963 Bytes
/
tcp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var net = require('net');
const express = require('express');
const path = require('path');
const ejs = require('ejs');
const cell_ip = '192.168.1.6';
const app = express();
const server = require('http').createServer(app);
const io = require('socket.io')(server);
app.use(express.static(path.join(__dirname, 'public')));
app.set('views', path.join(__dirname, 'public'));
app.engine('html', ejs.renderFile);
app.set('view engine', 'html');
app.use('/', (req,res) =>{
res.render('movingBall.html');
});
var client = new net.Socket();
client.connect(1234, cell_ip, function() {
console.log('Connected');
client.write('d2 ');
io.on('connection', socket => {
console.log(`Socket conectado: ${socket.id}`);
socket.on('cli', data =>{
client.write(data+"0");
})
});
server.listen(3000);
});
client.on('data', function(data) {
console.log('Received: ' + data);
});
client.on('close', function() {
console.log('Connection closed');
});