Initial commit.
This commit is contained in:
+136
@@ -0,0 +1,136 @@
|
||||
*.js
|
||||
|
||||
config.json
|
||||
|
||||
# ---> Node
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
.temp
|
||||
.cache
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Client for the [Sugoma's RAC protocol](https://bedohswe.eu.org/text/rac/protocol.md.html).
|
||||
|
||||
npx tsc && node . IP PORT
|
||||
@@ -0,0 +1,76 @@
|
||||
if (process.argv[2] == null) {
|
||||
console.log("No IP specified");
|
||||
process.exit(1)
|
||||
}
|
||||
if (process.argv[3] == null) {
|
||||
console.log("No port specified");
|
||||
process.exit(1)
|
||||
}
|
||||
const ip = process.argv[2];
|
||||
const port = Number(process.argv[3]);
|
||||
|
||||
class Message {
|
||||
readonly msg: string;
|
||||
readonly time: Date;
|
||||
readonly address: string;
|
||||
constructor(msg: string, time: Date, address: string) {
|
||||
this.msg = msg;
|
||||
this.time = time;
|
||||
this.address = address;
|
||||
}
|
||||
toString() {
|
||||
let d = this.time
|
||||
return "[" + d.getDate() + "." + (d.getMonth() + 1) + "." + d.getFullYear() +
|
||||
" " + d.getHours() + "." + d.getMinutes() +
|
||||
"] {" + this.address + "} "
|
||||
+ this.msg.replace("/\n/g", "$")
|
||||
}
|
||||
}
|
||||
|
||||
let messages: Message[] = [];
|
||||
|
||||
//const net = require('net');
|
||||
import * as net from "net";
|
||||
let srv = net.createServer(function(socket: net.Socket) {
|
||||
let addr = socket.address() as net.AddressInfo;
|
||||
if (!addr.hasOwnProperty('address')) {
|
||||
console.log("?!?!?!");
|
||||
socket.end();
|
||||
return;
|
||||
}
|
||||
socket.on('data', function(data: Buffer | string) {
|
||||
switch (data[0]) {
|
||||
case 0x30:
|
||||
let msg = new Message(String(data.slice(1)), new Date, addr.address);
|
||||
messages[messages.length] = msg;
|
||||
console.log("Got message: " + msg.toString());
|
||||
socket.end()
|
||||
return;
|
||||
case 0x31:
|
||||
let msize = 0
|
||||
for (const i of messages) {
|
||||
msize += i.toString().length + 1;
|
||||
}
|
||||
socket.write(String(msize));
|
||||
socket.end();
|
||||
console.log(addr.address + ", got size request. " + msize);
|
||||
return;
|
||||
case 0x32:
|
||||
console.log(addr.address + ", got messages request.");
|
||||
let str = "";
|
||||
for (const i of messages) {
|
||||
str += i.toString() + "\n";
|
||||
}
|
||||
console.log("Sending " + str.length + " to " + addr.address);
|
||||
socket.write(str);
|
||||
return;
|
||||
}
|
||||
console.log(addr.address + "???" + data[0]);
|
||||
});
|
||||
socket.on('error', function(e: Error) {
|
||||
console.log(e.stack);
|
||||
});
|
||||
})
|
||||
|
||||
console.log("Starting.");
|
||||
srv.listen(port, ip);
|
||||
Generated
+41
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "almatyd",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.10.2",
|
||||
"typescript": "^5.7.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "22.10.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.2.tgz",
|
||||
"integrity": "sha512-Xxr6BBRCAOQixvonOye19wnzyDiUtTeqldOOmj3CkeblonbccA12PFwlufvRdrpjXxqnmUaeiU5EOA+7s5diUQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"undici-types": "~6.20.0"
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.7.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz",
|
||||
"integrity": "sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.17"
|
||||
}
|
||||
},
|
||||
"node_modules/undici-types": {
|
||||
"version": "6.20.0",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz",
|
||||
"integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.10.2",
|
||||
"typescript": "^5.7.2"
|
||||
}
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig to read more about this file */
|
||||
|
||||
/* Projects */
|
||||
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
||||
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
||||
// "tsBuildInfoFile": "./.tsbuildinfo", /* S | ||||