how to use Redis Server Detection in laravel? - socket.io

1-Xampp
2-laravel 5.1
3-run localhost:8000
class in function
$redis = LRedis::connection();
$redis->publish('message', "fgfgff");
error
ConnectionException in AbstractConnection.php line 155:
No connection could be made because the target machine actively refused it. [tcp://127.0.0.1:6379]

If you are trying to create a connection between 2 host Redis is not an answer for you.
check out this question about what is Redis:
What is Redis and what do I use it for?
The problem with the Connection is probably because of the URL sending to the client side socket constructor.
change : var socket = io('http://localhost');
to : var socket = io();
Here is a link on step by step guide to use socket.io:
search "use socket.io with laravel" in Google.
To use connection between 2 host with Laravel you should use a package as it is not in Laravel by default.
this package enables push notification between server and devices like android or ios phones. here is the link to the package in GitHub:
davibennun/laravel-push-notification
Hope to be useful.
good luck.

Related

How to deploy and interact with a rust websocket?

I'm a beginner in Rust and WebSockets and I'm trying to deploy on Heroku a little chat backend I wrote (everything works on localhost). The build went well and I can see the app is running, and I'm now trying to connect to the WebSocket from a local HTML/Javascript frontend, but it is not working.
Here is my code creating the WebSocket on my rust server on Heroku (using the tungstenite WebSocket crate):
async fn main() -> Result<(), IoError> {
let port = env::var("PORT").unwrap_or_else(|_| "8080".to_string());
let addr = format!("0.0.0.0:{}", port);
// Create the event loop and TCP listener we'll accept connections on.
let try_socket = TcpListener::bind(&addr).await;
let listener = try_socket.expect("Failed to bind");
println!("Listening on: {}", addr);
and here is the code in my Javascript file that tries to connect to that WebSocket:
var ws = new WebSocket("wss://https://myappname.herokuapp.com/");
My web client gets the following error in the console:
WebSocket connection to 'wss://https//rocky-wave-51234.herokuapp.com/' failed
I searched to find the answer to my issue but unfortunately didn't find a fix so far. I've found hints that I might have to create an HTTP server first in my backend and then upgrade it to a WebSocket, but I can't find a resource on how to do that and don't even know if this is in fact the answer to my problem. Help would be greatly appreciated, thanks!
I think your mistake is the URL you use:
"wss://https://myappname.herokuapp.com/"
A URL usually starts with <protocol>://. The relevant protocols here are:
http - unencrypted hypertext
https - encrypted hypertext
ws - unencrypted websocket
wss - encrypted websocket
So if your URL is an encrypted websocket, it should start only with wss://, a connection cannot have multiple protocols at once:
"wss://myappname.herokuapp.com/"

Poloniex Push WAMP API through Autobahn dropping connection to peer tcp

I tried to connect to the Push API in poloniex using python and followed the instructions on the answer here:
How to connect to poloniex.com websocket api using a python library
However I keep getting this error:
2017-06-25T04:07:04 dropping connection to peer tcp:104.20.13.48:443 with abort=True: WebSocket opening handshake timeout (peer did not finish the opening handshake in time)
Anyone know what's going on here? I can't figure it out from online documentation. Thanks!
As per #Cyphrags suggestion, I was able to get my autobahn websocket to work outside of localhost by increasing openHandshakeTimeout with factory.setProtocolOptions
factory.protocol = MyClientProtocol
factory.setProtocolOptions(failByDrop=False, openHandshakeTimeout=90, closeHandshakeTimeout=5)
Solution found via https://github.com/crossbario/crossbar/issues/930. Perhaps the reason it is needed has something to do with slow DNS routing taking longer than the default handshake time.

Why is this websocket connection being refused?

I try to use the slack-sample bot from this blogpost https://www.opsdash.com/blog/slack-bot-in-golang.html . I've successfully created my api token, but i can not connect to the websocket server (the rtm.start request passs normally). I've get the error message
dial tcp 54.242.95.213:443: connectex: No connection could be made because the target machine actively refused it
I've also tried to connect via a chrome app called Simple Web Socket Client and via a website based one tester. Both work well, i can establish a connection and i can send data.
I'm behind a proxy, but i only have troubles with golang's websocket.Dial function.
Does anybody know why this can happen?
I use:
- Windows 7 SP1 x64
- Golang 1.7.1 windows/amd64
Greetings
Tonka
If you are using gorilla/websocket, it has the ability to use a Proxy. From issue 107:
import "net/http"
...
var dialer = websocket.Dialer{
Proxy: http.ProxyFromEnvironment,
}
If you are using golang.org/x/net you should switch to gorilla/websocket.

websocket behind reverse proxy alias

I installed a nodeJS server behind a reverse proxy with an alias.
Basically i'd like to reach my nodeJS server on : http://myapp.domain.intra/chat
but it seems that when, on the client, i do : var socket = io("http://myapp.domain.intra/chat",...)
the '/chat' is truncated and the connection tries to connect on the domain only : 'myapp.domain.intra', which does not work.
I do understand that basically the /chat is interpreted as a scope but how can I force socket IO take the /chat in account as the connection url?
Thanks
Ok, I found it. It's pretty easy.
I needed to set the path option like so :
var socket = io.connect("http://myapp.domain.intra",{path:'/chat/socket.io'});

websocket doesn't get connected

I could connect websocket to the server on my local machine. But when i uploaded the file to a remote ubuntu server, it doesn't work any more.
Server side code(server.php):
$master = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($master, SOL_SOCKET, SO_REUSEADDR, 1);
socket_bind($master, "127.0.0.1", 80);
socket_listen($master, 20);
client side code:
<script type="text/javascript">
var host = "ws://127.0.0.1:80/server.php";
socket = new WebSocket(host);
</script>
I open the client page from chrome canary version 24, server side didn't get any accepted socket.
I changed the host to "ws://xx.xx.xx.xx:80/server.php" to the real IP address of the server, doesn't work. Also changed the server side socket_bind($master, "127.0.0.1", 80) to real ip, no luck either.
Any one can help me?
Thanks,
Jasmine
My friend, when you write your server. You need to keep it running as a service or just keep it running.
In the case of a php server, you need to run that file from the PHP Cli (php yourfile.php), not from the browser (You can, setting the timeout to 0, but if you close the browser, your server stops working).
I really don't recommend a socket server over PHP. Read more about socket servers with C++ (QT, Berkeley), or Java Socket Servers.
When we are talking about HTML5 Websockets Server, it's different from programming a 'normal' socket server (There are a lot of libraries for PHP that can help you programming a HTML5 Websocket server)
https://github.com/Flynsarmy/PHPWebSocket-Chat
In that link, you can find an example of a chat. There is a file called class.PHPWebSocket.php, include it in your server.php and use that library for the creation of the HTML5 Websocket Server. See the examples, read how it works and how to use the class.PHPWebSocket.php (Take a look at the server.php file inside the examples).
Run the server when you finish it.
Then do:
// ...
var host = "ws://IP.OF.THE.SERVER:port";
socket = new WebSocket(host);
// ...
Read more about socket servers, HTML5 Websockets, and take a look at that class.PHPWebSocket.php utility.
Good Luck My Friend.

Resources