Skip to content

Commit

Permalink
Merge pull request #1 from Limitless-TCP/chunking
Browse files Browse the repository at this point in the history
Finished chunking and updated readme, also changed syntax to exactly …
  • Loading branch information
Bossslime authored Aug 14, 2023
2 parents 856314a + 10f73fe commit addc957
Show file tree
Hide file tree
Showing 4 changed files with 709 additions and 140 deletions.
44 changes: 38 additions & 6 deletions Examples/ClientExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,48 @@ let { TCPClient } = require('../Limitless-TCP');

let tcpClient = new TCPClient('127.0.0.1', 1234);

tcpClient.connect();
tcpClient.connect(() => {});

let str = "";


// for (let i = 0; i < 10000000; i++) {
// str += rand_str_without_O0();
// }
// console.log(str.length);

tcpClient.on('connect', () => {
tcpClient.emit({type: 'test', data: 'This is a test packet 1'});
tcpClient.emit({type: 'test', data: 'This is a test packet 2'});
tcpClient.emit('Yo 1');
tcpClient.emit('Yo 2');
tcpClient.write({ test: str })

// for (let i = 0; i < 1000; i++) {
// tcpClient.write('test')
// }

// tcpClient.write({ test: str });

tcpClient.on('data', (data) => {
console.log(data);
});
});

tcpClient.on('error', (err) => {
console.log(err)
//Handle error, heartbeat errors are formatted differently
});
});








function rand_str_without_O0() {
const list = "ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~`!@#$%^&*()_-+=}]{[|\"\\':;?/>.<,";
var res = "";
for(var i = 0; i < 12; i++) {
var rnd = Math.floor(Math.random() * list.length);
res = res + list.charAt(rnd);
}
return res;
}
35 changes: 28 additions & 7 deletions Examples/ServerExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,46 @@ let { TCPServer } = require('../Limitless-TCP');

let settings = {
useHeartbeat: true,
useCompression: true
useCompression: false,
useChunking: true
}

let tcpServer = new TCPServer(1234, settings); //The settings here will be applied to any clients that connect to the server

tcpServer.listen();
let str = "";


// for (let i = 0; i < 10000000; i++) {
// str += rand_str_without_O0();
// }
// console.log(str.length);

tcpServer.listen(() => {});

//Set to null because it is listening for a server event
tcpServer.on('connect', null, (socket) => {
tcpServer.on('connection', (socket) => {
socket.write({ test: str }, socket);

tcpServer.on('data', socket, (data) => {
socket.on('data', (data) => {
console.log(data)
});

tcpServer.on('error', socket, (err) => {
socket.on('error', (err) => {
console.log(err)
//Handle error, heartbeat errors are formatted differently and are per socket
});
});

tcpServer.on('error', null, (err) =>{
tcpServer.on('error', (err) =>{
//Handle error, heartbeat errors dont appear here
});
});

function rand_str_without_O0() {
const list = "ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~`!@#$%^&*()_-+=}]{[|\"\\':;?/>.<,";
var res = "";
for(var i = 0; i < 12; i++) {
var rnd = Math.floor(Math.random() * list.length);
res = res + list.charAt(rnd);
}
return res;
}
Loading

0 comments on commit addc957

Please sign in to comment.