I've made a websocket server with websocketpp (C++), and a websocket client in PHP. When I test it on my local machine it works: the client can connect to the server and they can send each other some data.
Then I placed the server-script on my server and compiled it there. After compiling it is running and "working": the server is also a client of another server, these connect and transfer data. However, my PHP client cannot connect to the C++ websocket server. I actually do not know which host URL to use. I've tried these:
ws://www.url.nl:port/folder/program-name
ws://www.url.nl:port/
ws://www.url.nl:port/program-name
How can I refer to my server?
I hope my problem is clear, but feel free to ask for clarifications if needed.
Then your url schould be ws://www.url.nl:port/
Make shure there is no firewall on your server/network which blocks your request. You can do this by running telnet www.url.nl port. If you have access to netcat use nc -v www.url.nl port this would give you much more verbose information on your connection status.
It would be very helpfull if you have any error messages. ;-)
EDIT running service:
Make shure your service is running and listen on correct network interface and port.
use netstat -tulpen on linux or netstat -ano on windows
EDIT check your firewall rules:
iptables -L
Related
I have created a Chat application in Ratchet PHP. It runs fine on local machine using WAMP. I want it to setup on live server.
On my server I have:
PHP Support
SSH access
Port 9000, which is opened for OutBound connections.
Sub-domains
What I don't have:
No port for InBound connections.
No root access in SSH. Say I cannot see/edit iptables
I ran php server.php which gives success message about the server is started and listening at port 9000. But when a HTML page tries to connect it using ws://domain:9000 it runs into error-
Firefox can’t establish a connection to the server at
ws://domain.com:9000/
I googled a lot and it appears that what I need is a port for inbound connections.
But according to this answer the thing I need is PHP support for Ratchet to work on shared hostings. Can anyone explains what I really need and Is there any workaround If it's not availble in the list of things I have on my server.
Basically, No
It is not likely for a shared hosting environment (i.e. Apache with VirtualHost config, PHP, MySQL, and a CPanel interface) to support your websocket application.
For websocket to work, you need to either:
have a port dedicated to websocket in-bound connections; or
have a HTTP/HTTPS server that knows when to upgrade a connection and proxy pass to your websocket application.
The first route requires the server to allow in-bound connection to a certain port number. This is a potential security issue for the hosting provider and, thus, is unlikely for your vendor to grant you that.
The second route requires Apache server have with both mod_proxy and mod_proxy_wstunnel installed and enabled. It also require you to use ProxyPass config, which cannot be overridden by .htaccess configs at all.
So unless your hosting grants you the permission to touch the Apache main configuration (or would apply such change for you), you're pretty hopeless.
Suggestion
To run your own websocket service, you should think about using Virtual Private Server services such as Amazon EC2, DigitalOcean VPS.
I need to make a TCP/IP socket server in PHP.
So I downloaded an example from php.net and tried it on my own machine (changed default script socket ip to 127.0.0.1). I opened it from web-browser (because I use XAMMP system, so I can't do a background working shell script), connected to 127.0.0.1:8175 by Telnet and it worked fine!
But now I have a problem:
I uploaded that script to remote server, opened port 8175 on the router and could not connect to the remote port from my computer. But I still can connect to the web and ssh ports on that server.
Any ideas?
If I asked that question in a wrong place, just say it. And... Sorry for my bad English.
If you set socket default IP to 127.0.0.1 you will be able to connect only from the machine running the script. So you need to change it something like your server's IP or 0.0.0.0 to accept all connections but take care of security measures.
I register in the Openshift.com and create a catridge. But when I need to deploy Mosquitto, a MQTT Server, which is accessed through tcp or ssl protocol, and I need visit from public IP.
Does Openshift just redirect http/https protocol through 80/443 port to 8080?
Is it possible to use socket communcation in Openshift?
I have created two applications in Openshift, one for push and the other for web deployment, and I stopped the apache service in order to let the mosquitto service listen to 8080. But only if I send post request in https protocol, It can access to the server for a while and disconnect.
I think this might point you in the right direction https://www.openshift.com/blogs/paas-websockets.
To save some readings from the readers, the steps involved in niharvey's answer:
Create a diy app in your openshift account.
Git checkout the code.
Add a websocket app of your own choice that would bind to $OPENSHIFT_DIY_IP:$OPENSHIFT_DIY_PORT.
Modify the action hooks for starting and stopping your app. Push the code.
From the client, connect to port 8000 for ws:// or 8443 for wss://, by your app url.
Just verified these steps do work as expected.
I am in the middle of building a website which means it is not uploaded to a server yet. Is there any way I can perform cross browser testing from the localhost and not an actual hosted URL?
Either by running lots of browsers natively (some in a VM), or by using SSH tunnelling to a commercial service like browserling (http://browserling.com/).
Edit to elaborate a bit: An SSH tunnel (a reverse tunnel technically) between your localhost and a server allows you to forward certain ports on the remote host to ports on your localhost, over an encrypted SSH channel. This means the browsers running on browserling's servers can send packets down the tunnel, back to your localhost and your webserver there.
Install PHP on your local machine, this way you can run PHP scripts in command-line or browsers.
http://php.net/manual/en/install.php
Configure your webserver to listen on your network IP and access your website through IP address on your local network.
If it is apache webserver It would be configured using directive:
Listen IP:port
Example 1 (your adapter IP address):
Listen 192.168.1.10:80
Example 2 (global listening on all interfaces) - better for testing
Listen 0.0.0.0:80
Then just simply access your computer from other browsers on other platforms.
Sure. If you're able to configure your local network you could expose port 80 or 443 to the cloud by making changes to your routers firewall. This would make your application as available for testing locally as any on a remote host.
Let me know if your question is about which tools you could use, either as external services or locally installable.
I have server A making a request to server B. I've tried both php's file_get_contents and curl; both refuse the connection. I'm trying to connect to a tomcat application on server B.
The connection does work if I make a request to google.com, or to another application on server B that is not in the Tomcat application.
This leads me to believe there's something specific to my tomcat installation that is rejecting the request from server A. Thoughts? Any more info I can provide to help with the problem?
Is there a way to whitelist my server A in tomcat so the connection is accepted? Or as a last resort how would I accept all requests?
Edit: I also wanted to add that the connection to server B works just fine when I'm connecting from my local development machine.
Your test from server A to google.com or other apps on server B probably use port 80. Many firewalls don't allow traffic on strange ports like 8089.
If you can't change the firewall rule to allow access to serverB:8089, I think the right way to do it is to proxy the request through the server B web server. So server A would request "serverB:80/yourproxyurl" and the web server on server B would talk to the tomcat server on localhost, and output the response.
This is what Tomcat Connectors are for, as I understand it.