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'});
Related
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/"
In my application, a client connects to the server at a given port and host.
Now, I want to know the port number that is opened at the client's end.
How can I get this information ?
Also, at the server end, can I also get the port number at which the client is connecting to ?
Basicaly, I want to send some extra information to the server when the client connects.. So, I will dump a file when a client is created with the file name as the port number of the client and at the server end, I will again try reading a file whose name is the port number of the client...
Now, I want to know the port number that is opened at the client's end.
Also, at the server end, can I also get the port number at which the client is connecting to ?
These questions seem to be the same to me. Unless you mean the port of the server, which you have to specify on both ends (and therefore already know).
Yes, you can get in your server the port of the connecting client along with the IP-address.
//boost::asio::ip::tcp::socket _socket;
_remoteAddress = _socket.remote_endpoint().address(); //You may call to_string() on it
_remotePort = _socket.remote_endpoint().port();
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.
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.
I would like to use the net/imap library in ruby behind a authenticated proxy, I was starting to dig in and I'm wondering if there is a way to do this already or if I need to make my own version of the net/imap library that supports a proxy?
It is possible to tunnel any socket connection through a HTTPS proxy server.
To do this:
open a socket to your proxy server
send "CONNECT hostname : portnumber HTTP/1.0\n\r\n\r\n"
read from the socket until you see the end of the HTTP headers (2 blank lines)
your socket is now connected
Here is a ruby example of such a tunnel.
Reasons this will fail:
most network admins will only allow CONNECT to port 443
proxy server has proxy authentication
The easiest way to hack libraries that don't support proxy information is to replace Net::HTTP with an instance of Net::HTTP::Proxy:
# somewhere before you load net/imap
proxy = Net::HTTP::Proxy(address, host)
Net.class_eval do
remove_const :HTTP
HTTP = proxy
end