Skip to content

Commit 5f9f31f

Browse files
author
potatoTVnet
committed
added sending capabilities
1 parent 61677f2 commit 5f9f31f

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# [EXPERIMENTAL] RemoteServer
22

33
currently only relaying tcp packages on the console, might be used for data analysis, game state sharing or other second-screen experiences later...
4+
5+
start program by running ``npm start``

app.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
1+
const readline = require('readline').createInterface({
2+
input: process.stdin,
3+
output: process.stdout
4+
})
15
const Net = require('net')
2-
const port = 12000
6+
const port = 12001
37

48
const server = new Net.Server()
59

6-
server.listen(port, function() {
10+
server.listen(port, function () {
711
console.log(`Server listening for connection requests on socket localhost:${port}`)
812
})
913

10-
server.on('connection', function(socket) {
11-
console.log('A new connection has been established.')
14+
server.on('connection', function (socket) {
15+
console.log('CONNECTED')
16+
17+
socket.on('data', function (chunk) {
18+
console.log(`${chunk.toString()}`)
19+
})
1220

13-
socket.on('data', function(chunk) {
14-
console.log(`Data received from client: ${chunk.toString()}`)
21+
socket.on('end', function () {
22+
console.log('CONNECTION CLOSED')
1523
})
1624

17-
socket.on('end', function() {
18-
console.log('Closing connection with the client')
25+
socket.on('error', function (err) {
26+
//console.log(`Error: ${err}`)
1927
})
2028

21-
socket.on('error', function(err) {
22-
console.log(`Error: ${err}`)
29+
readline.on('line', function (input) {
30+
if(input == "Q") process.exit(1)
31+
socket.write(input)
2332
})
24-
})
33+
34+
})
35+

index.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33

44
<head>
5-
<title>Title</title>
5+
<title>Remote State Logging</title>
66
<meta charset="utf-8">
77
<meta name="viewport" content="width=device-width, initial-scale=1">
88
<!-- UIkit CSS -->
@@ -12,8 +12,6 @@
1212
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/uikit.min.js"></script>
1313
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/uikit-icons.min.js"></script>
1414

15-
<script src="app.js"></script>
16-
1715
</head>
1816

1917
<body>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"start": "node app.js"
88
},
99
"keywords": [],
1010
"author": "",

0 commit comments

Comments
 (0)