alemures / fast-tcp Goto Github PK
View Code? Open in Web Editor NEWfast-tcp is an extremely fast TCP client and server that allows to emit and listen to events
fast-tcp is an extremely fast TCP client and server that allows to emit and listen to events
Hey, I noticed the project is not being actively maintained recently so I'm not sure you're reading this, How would you go about adding a TTL feature to the protocol? I'm thinking of adding it myself and was wondering what would be the best way. The purpose is to trigger an error after emit if a given number of ms has passed. I can implement this by wrapping the response without a setTimeout but the message would still exist in the queue and pass on to the server
In the following sample code no messages are sent after the 10th or 11th run.
Tested on MacOS 10.12.4 / Node 6.10.x / Electron 1.6.7
SERVER:
import { createWriteStream } from "fs";
const server = new Server();
server.on('connection', (socket) => {
console.log('connected');
socket.on('image', function (readStream, info, callback) {
const rootPath = '/Users/thomas/Documents/Temp/';
let writeStream = createWriteStream(rootPath + info.name);
readStream.pipe(writeStream);
writeStream.on('finish', () => {
callback('image transfer successfully');
});
});
});
server.listen(5000);
CLIENT:
import { createReadStream } from "fs";
const socket = new Socket({
host: 'localhost',
port: 5000
});
socket.on('connect', () => {
let counter = 1;
setInterval(() => {
const testFile = '/Users/thomas/Documents/test.jpg';
let writeStream = socket.stream('image', { name: Math.random() + '-test.jpg' }, (result) => {
console.log('answer from server: ', result);
});
createReadStream(testFile).pipe(writeStream);
console.log('file transfered: ', counter);
counter++;
}, 5000);
});
Hi Alejandro:
I'm confused when reading your source code, and I have a questions:
In "Server.js", the Server object have a prototype function "_superEmit". Which object will it emit msg to ?
Thank you!
Hello Alemures,
Here a is a feature i though for fast-tcp:
Create a sort of router allowing to share messages trough different network interfaces (contextes).
Example: when you want to run the same service on a socket file and on tcp socket
All the best
Docs doesn't descibe the login event an its handling...
I see fast-tcp is awesome! Can we connect client from LUA (mobile game engine using LUA) to fast-tcp server?
Thank so much!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.