brharp / jsh Goto Github PK
View Code? Open in Web Editor NEWJavaScript Shell
JavaScript Shell
websockd upgrades to a websocket connection and then writes data to stdout and reads data from stdin. The websocket protocol interleaves data with framing information. websockd removes framing information from the downstream and inserts framing into the upstream. websockd is essentially a state machine. Each byte of data read from the socket can either be: - Opcode/flags - Content length data - Masking key data - Payload data Payload data is copied to stdout. Each byte of data read from stdin is payload data and is appended to the frame. Newline (\n) serves as a record separator. When a newline is read, a frame is queued for output to the socket. What we end up with is a linked list of frames from the socket ready to be written to stdout, and a linked list of frames from stdin ready to be written to the socket. When select indicates that a file descriptor is ready for reading or writing, we drain the output queue or add to the input queue. The core of the program is a call to select(). If we have any incoming frames ready to be written, we ask the pipe if it is available for writing. Likewise, if we have any outgoing frames ready we ask the socket if it is ready to be written to. We always ask the socket and stdin if they have data available to be read---if so we read what they have and add to the queue. From the pipe we read and write plain text, delimited by newlines. From the socket we read and write frames. This adapts the web API's clunky message oriented interface to a stream of text that UNIX programs can understand. Data Structures incoming queue outgoing queue incoming frame buffer outgoing frame buffer incoming line buffer outgoing line buffer outgoing frame content length incoming frame content length Program Structure (Prepare to run as a daemon.) Create a socket server and listen for connections. Fork a new process per client connection. Perform websocket handshake. Fork a second time and exec service. Proxy frames between client and service. Receiving Data Buffer empty? Read frame header Read _content length_ bytes of payload data Return up to n bytes of data to caller Sending Data Write frame header Write n bytes of data
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.