Comments (9)
Good question. In the screencast, I created a file called terminal.html
that opens up a WebSocket connection simply by calling the WebSocket()
constructor. i.e.,
var connection = new WebSocket('ws://localhost:7890');
So here's a complete client-side example. First start gwsocket
.
gwsocket --echo-mode
Then create an html file, e.g., echo.html
.
<!DOCTYPE html>
<html lang="en">
<style>
pre {
background: #EEE;
border: 1px solid #CCC;
padding: 10px;
}
#page-wrapper {
border-top: 5px solid #69c773;
margin: 1em auto;
width: 950px;
}
</style>
<script>
window.onload = function() {
function $(selector) {
return document.querySelector(selector);
}
var socket = new WebSocket('ws://localhost:7890');
socket.onopen = function(event) {
$('#messages').innerHTML = 'Connected<br>';
};
socket.onmessage = function(event) {
$('#messages').innerHTML += 'Received:<br>' + event.data + '<br>';
};
socket.onclose = function(event) {
$('#messages').innerHTML = 'Disconnected ' + event.reason;
};
$('#submit').onclick = function(e) {
socket.send($('input').value);
$('#messages').innerHTML += 'Sent:<br>' + $('input').value + '<br>';
$('input').value = '';
};
};
</script>
<div id="page-wrapper">
<pre id="messages">Connecting...</pre>
<input id="message" required>
<button id="submit">Send Message</button>
</div>
Then open the file in your browser (Ctrl+o should do it), it will connect to the server in echo-mode. BTW, you can find the same example here.
Now, If you are looking to have your full terminal output displayed in the browser, you need to load hterm.js
. You can get a copy and the example here.
I'll update the man page so it's a bit more obvious :)
from gwsocket.
I will try it, the way you described, but from what I understood gwsocket needs to be run on the remote server where I want to tail the logs (e.g)
then in my local PC, I thought I would connect my browser to the remote server, to bring the logs to my browser eventually I could run a local webserver or throw the local HTML file to local browser
and inside the HTML I would have the code above where I would change var socket = new WebSocket('ws://REMOTESERVER:7890');
should this work ?
is there any complient browser required, I tried FF & CHROME and I and had
where do I reference http://gwsocket.io/hterm/hterm.js in the HTML ?
I am running my PC in windoes and though this setup is independent and local client PC only requires browser and possibly an HTML file
anyway, it will be cool once I get it working
good work
cheers
-Duro
from gwsocket.
server side
window one: gwsocket --echo-mode OR just gwsocket
window two: top > /tmp/wspipein.fifo
window three: netstat
tcp 0 0 0.0.0.0:7890 0.0.0.0:* LISTEN 30156/gwsocket
the transition files are create in /tmp
run all as root my local pc side create your echo.html
file - replace
var socket = new WebSocket('ws://http://REMOTESERVERIP:7890/');
browser - either run my local webserver to point to your echo.html or, just throw it to the browser from filesystem
not sure where I am making mistake/wrong assumption
many thanks
-Duro
from gwsocket.
Seems like the problem might be with
new WebSocket('ws://http://REMOTESERVERIP:7890/');
You don't need to use the http://
nor the trailing /
, so please try,
new WebSocket('ws://REMOTESERVERIP:7890');
from gwsocket.
Also, please make sure you're not blocking port 7890
in your server.
from gwsocket.
Perfect
works pretty well now
the damn "/" at the end was causing an issue
mine minimalistic version of the HTML is (deos not include commands communication, just outputs your pipe to /tmp/wspipein.fifo - e.g. vmstat 1 > /tmp/wspipein.fifo)
<!DOCTYPE html>
<html lang="en">
<style>
pre {
background: #EEE;
border: 1px solid #CCC;
padding: 10px;
}
#page-wrapper {
border-top: 5px solid #69c773;
margin: 1em auto;
width: 950px;
}
</style>
<script>
window.onload = function() {
function $(selector) {
return document.querySelector(selector);
}
var socket = new WebSocket("ws://192.168.19.21:7890");
socket.onmessage = function(event) {
$("#messages").innerHTML += "" + event.data;
};
};
</script>
<div id="page-wrapper">
<pre id="messages"></pre>
</div>
</HTML>
from gwsocket.
Hey
many thanks for your help
the only issue, but that is more of an HTML issue is to hwo to keep the browser page small
this is piping lines tothe HTML via $("#messages").innerHTML += "" + event.data;
so if the output from the server is fast, browser could crash
I think it will be solved via refresh of the page regularily or size of the frame
in any ways
good job !
-Duro
from gwsocket.
plus I am sure you have plans of sending data back via browser to your oprocess via /tmp/wspipeout.fifo to control the process
looking forward to the new version of goaccess using this
cheers
-Duro
from gwsocket.
Glad to hear that worked. You can do kinda like what I do on the gwsocket.io site to not keep adding stuff to the browser...
var socket = new WebSocket('ws://localhost:7890');
function addMessage(msg) {
// current messages
var msgs = $('.container .message');
// keep the last 20 lines
if (msgs.length == 20)
msgs.first().remove();
$('<div />', {
'class': 'message'
})
.html(msg)
.appendTo($('.wrapper'));
}
socket.onmessage = function(event) {
var lines = event.data.split(/\n/);
for (var i = 0; i < lines.length; ++i)
$.trim(lines[i]) != '' && addMessage($.trim(lines[i]));
};
from gwsocket.
Related Issues (20)
- Serving files via sendfile HOT 2
- Using in multible domains on one port HOT 3
- Fails to compile with OpenSSL 1.1.0 or newer HOT 3
- gwsocket+apache: status 200 instead of 101 HOT 2
- Strict protocol parsing HOT 7
- Support for multiple instances? HOT 8
- Is webshell considered to be integrated into the project? HOT 2
- Feature request - client version of gwsocket (same style as gwsocket, but client, not server)
- " unrecognized option `--ssl-cert' " HOT 13
- make fails on Ubuntu 20. HOT 3
- TAR Download broken HOT 2
- -Wno-missing-field-initializers on SPARC machine HOT 5
- Help with FIFO Error. Bad address HOT 11
- How can I get the same text formatting effect as on the website? HOT 2
- gwsocket as a library HOT 7
- gwsocket.io: :( Nope, the connection is out. Try again later! HOT 2
- Typo on the webpage HOT 1
- windows bianries?
- API to disconnect client in strict mode HOT 3
- feedback
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gwsocket.