network stuff?
This commit is contained in:
		
							parent
							
								
									6c7bbc2304
								
							
						
					
					
						commit
						2a6f2d6f9b
					
				
					 3 changed files with 42 additions and 16 deletions
				
			
		|  | @ -1,18 +1,22 @@ | ||||||
| import * as https from 'https'; | import * as net from 'net'; | ||||||
| 
 | 
 | ||||||
| const options = { | const hostname = '192.168.1.219'; | ||||||
| 	hostname: '192.168.1.219', | const port = 29999; | ||||||
| 	port: '29999', | 
 | ||||||
| 	path: '/', | function getBinarySize(string) { | ||||||
| 	method: 'POST', | 	return Buffer.byteLength(string, 'utf8'); | ||||||
| 	headers: { | } | ||||||
| 		'Content-Type': 'application/json', |  | ||||||
| 	}, |  | ||||||
| }; |  | ||||||
| 
 | 
 | ||||||
| export default function req(data, callback, errorCallback) { | export default function req(data, callback, errorCallback) { | ||||||
| 	const request = https.request(options, (res) => callback(res)); | 	let string_data = JSON.stringify(data); | ||||||
| 	request.on('error', (error) => errorCallback(error)); | 	let size = getBinarySize(string_data); | ||||||
| 	request.write(JSON.stringify(data)); | 
 | ||||||
| 	request.end(); | 	let client = new net.Socket(); | ||||||
|  | 	client.connect(port, hostname, () => { | ||||||
|  | 		let res = client.write(size); | ||||||
|  | 
 | ||||||
|  | 		if (res) { | ||||||
|  | 			client.write(string_data); | ||||||
|  | 		} | ||||||
|  | 	}); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,12 +1,12 @@ | ||||||
| { | { | ||||||
|   "type": "module", |   "type": "module", | ||||||
|   "dependencies": { |   "dependencies": { | ||||||
|     "eris": "^0.14.0" |     "eris": "^0.14.0", | ||||||
|  |     "socket.engine": "^1.0.0" | ||||||
|   }, |   }, | ||||||
|   "name": "lights", |   "name": "lights", | ||||||
|   "version": "1.0.0", |   "version": "1.0.0", | ||||||
|   "main": "bot.js", |   "main": "bot.js", | ||||||
|   "devDependencies": {}, |  | ||||||
|   "scripts": { |   "scripts": { | ||||||
|     "test": "echo \"Error: no test specified\" && exit 1", |     "test": "echo \"Error: no test specified\" && exit 1", | ||||||
|     "start": "node bot.js" |     "start": "node bot.js" | ||||||
|  |  | ||||||
							
								
								
									
										22
									
								
								pnpm-lock.yaml
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										22
									
								
								pnpm-lock.yaml
									
										
									
										generated
									
									
									
								
							|  | @ -1,5 +1,6 @@ | ||||||
| dependencies: | dependencies: | ||||||
|   eris: 0.14.0 |   eris: 0.14.0 | ||||||
|  |   socket.engine: 1.0.0 | ||||||
| lockfileVersion: 5.1 | lockfileVersion: 5.1 | ||||||
| packages: | packages: | ||||||
|   /eris/0.14.0: |   /eris/0.14.0: | ||||||
|  | @ -13,11 +14,31 @@ packages: | ||||||
|       tweetnacl: 1.0.3 |       tweetnacl: 1.0.3 | ||||||
|     resolution: |     resolution: | ||||||
|       integrity: sha512-/W6X0SFR2swtA9oc4ga5Wh1TQcZtPgbUaDDdwYc67fvFUAtwC+V1xzWUZq2yDeJnTfB8Uot9SJWA8Lthe2sDtQ== |       integrity: sha512-/W6X0SFR2swtA9oc4ga5Wh1TQcZtPgbUaDDdwYc67fvFUAtwC+V1xzWUZq2yDeJnTfB8Uot9SJWA8Lthe2sDtQ== | ||||||
|  |   /fs/0.0.1-security: | ||||||
|  |     dev: false | ||||||
|  |     resolution: | ||||||
|  |       integrity: sha1-invTcYa23d84E/I4WLV+yq9eQdQ= | ||||||
|  |   /ip/1.1.5: | ||||||
|  |     dev: false | ||||||
|  |     resolution: | ||||||
|  |       integrity: sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo= | ||||||
|  |   /net/1.0.2: | ||||||
|  |     dev: false | ||||||
|  |     resolution: | ||||||
|  |       integrity: sha1-0XV+yaf7I3HYPPR1XOPifhCCk4g= | ||||||
|   /opusscript/0.0.7: |   /opusscript/0.0.7: | ||||||
|     dev: false |     dev: false | ||||||
|     optional: true |     optional: true | ||||||
|     resolution: |     resolution: | ||||||
|       integrity: sha512-DcBadTdYTUuH9zQtepsLjQn4Ll6rs3dmeFvN+SD0ThPnxRBRm/WC1zXWPg+wgAJimB784gdZvUMA57gDP7FdVg== |       integrity: sha512-DcBadTdYTUuH9zQtepsLjQn4Ll6rs3dmeFvN+SD0ThPnxRBRm/WC1zXWPg+wgAJimB784gdZvUMA57gDP7FdVg== | ||||||
|  |   /socket.engine/1.0.0: | ||||||
|  |     dependencies: | ||||||
|  |       fs: 0.0.1-security | ||||||
|  |       ip: 1.1.5 | ||||||
|  |       net: 1.0.2 | ||||||
|  |     dev: false | ||||||
|  |     resolution: | ||||||
|  |       integrity: sha512-vwc9JVBNe33686TBl9T3Ro53FaF09z11NVnrf0HIlYUOIDaZ1OFA1J1O6igU57qhP3NyUv4a+kZtgMm6SnziaQ== | ||||||
|   /tweetnacl/1.0.3: |   /tweetnacl/1.0.3: | ||||||
|     dev: false |     dev: false | ||||||
|     optional: true |     optional: true | ||||||
|  | @ -39,3 +60,4 @@ packages: | ||||||
|       integrity: sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA== |       integrity: sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA== | ||||||
| specifiers: | specifiers: | ||||||
|   eris: ^0.14.0 |   eris: ^0.14.0 | ||||||
|  |   socket.engine: ^1.0.0 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue