Can't make socket connection
grupodeca opened this issue · 21 comments
Hi,
I've installed gwsocket following these instructions:
$ wget http://tar.gwsocket.io/gwsocket-0.2.tar.gz
$ tar -xzvf gwsocket-0.2.tar.gz
$ cd gwsocket-0.2/
$ ./configure
$ make
$ make install
Then I run the program like this:
$ gwsocket &
Check if the process is started and socket is listening:
$ ps ax | grep gwsocket
2925 pts/0 S 0:00 gwsocket
2936 pts/0 S+ 0:00 grep gwsocket
$ netstat -atn | grep 7890
tcp 0 0 0.0.0.0:7890 0.0.0.0:* LISTEN
But when using your html example the connection to the socket fails. The html file throws the following error:
WebSocket connection to 'ws://localhost:7890/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
window.onload @ terminal.html:20
The code from line 20 is:
var socket = new WebSocket('ws://localhost:7890');
As far as I know iptables is off and firewall is off too.
$ service iptables status
iptables: Firewall is not running.
$ cat /etc/redhat-release
CentOS release 6.9 (Final)
$ uname -a
Linux centosdev.localdomain 2.6.32-696.30.1.el6.x86_64 #1 SMP Tue May 22 03:28:18 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
What is missing? Why I can't establish the connection?
Regards,
-Gerardo
Here's what I did on a vanilla Arch Linux box:
$ wget http://tar.gwsocket.io/gwsocket-0.2.tar.gz
$ tar -xzvf gwsocket-0.2.tar.gz
$ cd gwsocket-0.2/
$ ./configure --enable-debug
$ make
# make install
then I created a file on the home folder called echo.html
and pasted this:
<!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 I ran this:
$ gwsocket --echo-mode
I opened the echo.html
on Chrome (Ctrl+o) and I was able to connect fine and echo the input.
Are you running this example? If so please try --echo-mode
and build with ./configure --enable-debug
.
Hi,
I did what you wrote. I ran it as root and I got this message:
[root html]# gwsocket --echo-mode
Unable to open fifo out: No such device or address.
For obvious reasons the echo.html page showed the disconnected message.
How can I fix it?
Regards,
-Gerardo
Can you please try running gwsocket as root? Usually the ERR_CONNECTION_REFUSED message is due to some sort of permission or blocking on the server side.
Hi,
That's exactly what I did and still having the problem of ERR_CONNECTION_REFUSED.
Any other ideas to solve this issue?
Regards,
-Gerardo
ERR_CONNECTION_REFUSED
is standard when the port is closed, or it could be rejected because SSL/TLS is failing.
How are you opening the HTML file? via file:///
or through a webserver?
Hi,
What SSL/TLS packages should the Linux server have installed?
These are the current ones:
[root ~]# yum list installed | grep -i "ssl|tls"
gnutls.x86_64 2.12.23-21.el6 @base
nss_compat_ossl.x86_64 0.9.6-2.el6_7 @base
openssl.x86_64 1.0.1e-57.el6 @base
perl-Crypt-SSLeay.x86_64 0.57-17.el6 @anaconda-CentOS-201508042137.x86_64/6.7
pyOpenSSL.x86_64 0.13.1-2.el6 @anaconda-CentOS-201508042137.x86_64/6.7
I am opening the HTML file through a webserver using the local IP, something like this http://172.30.0.7/echo.html
Regards,
-Gerardo
Hi,
In this case the Linux server is virtualized in my MAC using Parallels. But I try before on another Linux server that is virtualized on the Rackspace's Cloud. Both have the same error ERR_CONNECTION_REFUSED.
Regards,
-Gerardo
You don't need SSL unless you are making a wss connection or if you are opening the URL from https.
It sounds though as there's something that's it's not letting the connection go through. Are you able to try this on your local machine (assuming you are running *nix)? or if you can try this on a bare-metal machine would be great. I'll spin up a CentOS 6.9 and see how it goes.
Hi,
I will try on my macOS and I will let you know my findings.
Regards,
-Gerardo
You know what, I have running goaccess app on a CentOS 6.9 which is under Vmware and the real time feature runs perfect, which is working using gwsocket.
Just tested this on a vanilla CentOS 6.9 and I can confirm it works fine.
$ uname -a
Linux localhost.localdomain 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21 05:29:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/centos-release
CentOS release 6.9 (Final)
This most be an isolated issue or specific to your setup. If you can share the steps to reproduce this on any *nix machine, I can look into it.
Any updates on this?
Closing this. Feel free to reopen it if needed.
BTW, v0.3 has been deployed if you would like to give it a shot.
I am having the exact same issue.
I have done every step as @grupodeca and found that the connection is not established.
The strange thing is that if I install the gwsocket on my local machine (linux ubuntu) - works just fine. This problem appears only on a remote machine (droplet) also linux ubuntu. I can't seem to establish the connection.
@StefanIvic93 I deployed some changes upstream not long ago. Are you experiencing this issue if you build from development?
I tried to build from dev before, but just to be sure, I tried it now again. Still the same issue.
@StefanIvic93 could you please share how you are running gwsocket and what's the output from your browser's console? any other info you may have, please feel free to share it. Thanks
Here is what I did:
$ git clone https://github.com/allinurl/gwsocket.git
$ cd gwsocket
$ autoreconf -fiv
$ ./configure
$ make
$ make install
After that I created an html file - logs.html. I put that file in my /var/www/logs directory since I am using the apache.
simple html copied from this issue ---> #9
I start the gwsocket server
gwsocket &
tailf -f /var/log/apache2/access.log > /tmp/wspipein.fifo &
Then I go back to the browser and navigate my IP address /logs.html ----> practically http://localhost/logs.html --- I get Disconnected.
I also tried accessing it from the terminal ----> lynx http://localhost/logs.html ---> Connecting... and nothing happens.
In the console I get:
https://ibb.co/dBmfjY0
https://ibb.co/GQ29g98
https://ibb.co/nwdSwfg
https://ibb.co/RYvLsqtaew
Thanks for the help!
@StefanIvic93 it looks like you got the address wrong on the ws connection, you should set it as below since you are trying to reach the WS server and not your local machine. Also, make sure to open port 7890 on your server.
var socket = new WebSocket('ws://160.90.228.141:7890');
If that doesn't help, after running gwsocket, are you able to telnet to that specific IP addresss from your local machine? e.g.,
# telnet 160.90.228.141 7890
That was the problem! Of course, it is so logical, it can not connect to anything on local host since I have the server started on a remote machine!
Thank you so much!
Could you also tell me a good way to format the output of the log? This terminal.html that you are using in a demo, which shows exactly the same output, colours and stuff as you get in the actual terminal. Is that file up for grabs or ? :)
@StefanIvic93 please take a look at this post for that terminal output.