VulpesOS/gaia/tests/jsmarionette/client/sockit-to-me/example.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

25 lines
671 B
JavaScript
Executable file

'use strict';
// Import the add-on.
var sockittome = require('./');
// Create a new sockit object.
var sockit = new sockittome.Sockit();
// Connect to a host and port.
sockit.connect({ host: 'www.google.com', port: 80 });
// Write some data! Takes either a String or a node.js 'Buffer' object.
sockit.write('GET / HTTP/1.0\r\n\r\n');
//sockit.write(new Buffer('GET / HTTP/1.0\r\n\r\n'));
// Read some tasty bytes! Returns a node.js 'Buffer' object, always.
var buffer = sockit.read(1024);
// Observe amazing results.
console.log('Read ', buffer.length, ' bytes');
// And beautiful raw HTTP response.
console.log(buffer.toString());
// Close it up.
sockit.close();