A few days ago I setup this WebSocket server from http://code.google.com/p/phpwebsocket/
It works excellent on my localhost by using Xampp. Then, I uploaded it to my webspace on Strato, but now I am not able to connect to the server.
I changed the the sockets connection to my domain but it didn`t work
Client.html:
var host = "ws://xxxxxxxx.com:12345/Websocket/server.php";
Server.php:
$master = WebSocket("xxxxxx",12345);
I already tried it with different port(80,443,12345,8080,8000....), using the IP address in server.php instead of the domain.
I also used absolute and relative paths in the client.html.
From the projects page http://code.google.com/p/phpwebsocket/ someone suggested to use 0 or 0.0.0.0 in the server.php, but that didn`t work either.
In the client.html it just shows:
WebSocket - status 0
Disconnected - status 3
My guess that the problem is that Strato is blocks me from using WebSockets.
Is it possible to run WebSockets on my webspace?
My bet is that your host is blocking incoming requests to the socket. Your not supposed to run scripts like phpwebsocket within a web service (it is a server itself). This confuses a lot of people since PHP is typically used for scripting webpages, not for coding daemons.
I say this because you mentioned running the script within Xampp, and referred to your hosting service as 'webspace'.
If this is the case you will have to upgrade to a virtual server package so that you can run your own services.
Okay, to bring this to an end.
I found a solution to use my websockets app and I´ve got an explanation why it did not work on my shared hosting solution.
I contacted Strato who told me that they don`t allow Websocket on shared hosting. The only way to get a similiar result would be to use AJAX Long Pooling.
Now I purchased to a Virtual Server and my websocket app works great now.
Thanks for your support.
Related
I'm at a complete loss as to why this is failing, so get ready for the novel describing exactly what I'm trying to accomplish and what I've tested so far.
Goal:
I'm building a webpage on my GoDaddy hosting account that I want to connect to my locally hosted Radarr server's API via PHP cURL.
I want to use PHP so I can obfuscate the IP, port, and APIKey on the client side. Plus, some of Radarr's API calls I would like to use cannot be run via query string.
Problem:
No matter what I try, I am getting nothing but the following error:
Failed to connect to <MY PUBLIC IP ADDRESS> port <PORT NUMBER>: Connection refused
(And yes, this is the publicly opened port, not the internal port on the server.)
Setup:
I installed Radarr on a FreeNAS (11.3-U5) jail hosted in my home. This is working beautifully.
I setup the FreeNAS jail with a dedicated IP address instead of allowing it to NAT internally, just to make sure it doesn't cause any issues.
I configured port forwarding on my router to allow external traffic into the Radarr server. This is working. Note: Xfinity is my ISP, but I purchased the router separately.
I have a GoDaddy hosting account where I've written a webpage to tie into Radarr's API on my local network. Currently, the webpage is also working beautifully to query data from the API, BUT it's connecting to Radarr via $.getJSON with JavaScript and jQuery.
(Before anyone says it, yes, I know GoDaddy hosting isn't the best option, but it's the one I'm using.)
Testing:
I swear I've tested EVERYTHING and I don't know why this is failing.
This IS working through the JavaScript/jQuery solution, meaning the Radarr server is up and running, the port is properly forwarded through my router, and GoDaddy's hosting isn't blocking the connection.
I CAN access the raw JSON API response in the browser simply by entering the full API URL call.
And while I'd say I am versed in PHP, I'm certainly no expert, so I even tried pulling a generic PHP cURL script from another StackOverflow post, changing the URL to mine, and running that with no luck. Note: The original script DID work to connect to another external API though.
Then I tried Postman, which worked, and I used Postman to create a PHP script, but that script failed.
All of the functional testing done on my local network was done using my publicly facing IP address. However, just to be certain, I also tried reaching the API through the browser off my network, and that worked just fine.
In a desperate attempt, I also reached out to GoDaddy support to see if they had any ideas. They went as far as creating a test PHP cURL script in the same hosting directory and had it simply pull Google's homepage. That worked just fine.
After GoDaddy was unable to help, I setup a free hosting account and free subdomain on AwardSpace, uploaded the script, and that failed too.
In digging into the Connection Refused error, someone suggested just trying to ping the IP through PHP. I attempted this, but it returned 100% packet loss. Also, I logged into my router and watched the incoming connections as I tested. Using the jQuery solution, I saw the incoming connection and it worked great. Using the PHP solution, it didn't register anything inbound.
Lastly, I have confirmed that the publicly opened port on my router is in the list of blocked port by Xfinity. However, since I can access the server externally through the browser and via the jQuery script, that can't be the issue.
There seem to be many, many, many articles online about the general Connection Refused error, but I haven't found a solution to my problem from any of them.
Does anyone have any suggestions?
I've written a webapp in php, which works as a standalone app, but needs to get/post new data from time to time to an API (written by a different company, for desktop software) on localhost. When connecting, it would be from a webpage/browser open on that machine.
So far I've attempted to send curl requests, basically using the generated postman curl code, and it's returning false. I'm thinking it's because it can't connect to the localhost server, possibly because it's blocked from the internet.
I've been researching for a few days, but want a solution that doesn't involve me creating security vulnerabilities in the computers I am trying to connect to, by opening them directly to the internet, and if there is a way to send requests to localhost without installing more software on them I would be partial to that kind of setup.
Does this make sense? I hope someone has some experience or wisdom in this area that could at least nudge me in the right direction.
The localhost is always the computer where you refer to that host. You can't connect to the localhost from your webapp, because the localhost hostname for that app is the computer which runs it.
You have to open a tunnel from you computer to the internet where you webapp can communicate with it.
You can use ngrok to do that, for example
I am trying to expose my website to internet, using ngrok, my website lives in xampp server which is running on my local machine. the path to my website is this: C:\xampp\htdocs\TheWebsite
when i use the following command for running ngrok client:
ngrok http -host-header=rewrite TheWebsite:8081
the client gets connected to ngrok server, but when i try to access my website on internet using http://234k2h4k24.ngrok.io which is the url ngrok provides for me, i end up with this error:
The connection to http://234k2h4k24.ngrok.io was successfully tunneled to your ngrok client, but the client failed to establish a connection to the local address TheWebsite:8081.
Make sure that a web service is running on TheWebsite:8081 and that it is a valid address.
The error encountered was: dial tcp: lookup TheWebsite: no such host
how exactly one should set the value for -host-header switch in order to to get the sub-directories (websites) living in htdocs folder in xampp server environment??
I have searched this site and also all over the Internet and i found some quick answers but they confused me even more. like this one:
https://helgesverre.com/blog/expose-local-webserver/
which doesn't even provide a small example
and this: Tunnel a localhost subdirectory through ngrok?
just the same as previous one (no example)
A real good answer needs to provide at least one complete example (i mean, if you want to answer this question, please provide a full example of ngrok command for the path of my website (TheWebsite). thank you
for this purpose i needed to define virtual hosts for each of my websites!
I found the answer in a related question at stackoverflow.com and here it is:
Tunnel a localhost subdirectory through ngrok?
this question leads you to this page which lets you know how to define virtual hosts in order for your local machine to identify where is the requested website, just take a look and you will learn in it no time. here is the page:
http://forum.wampserver.com/read.php?2,127757
although its for wamp but it is the same for xampp server too!
I have hosted website and api on apache server on linux machine. I am trying to access the api through node js (using request module)which is on the same network. From outside that network, the api is accessible and working fine. I have many apis on the machine and only few are throwing this error. Recent change which was made to server is changing the cookie domain from foo.bar.com to *.bar.com in php.ini file. The website is working good. There is not much load on the server too. Any help appreciated.
A "connection refused" error means a TCP connection can't be established, so the cookie domain change should not have an effect here.
Are you sure it's a Node.js "connection refused" error, and not, say, the API itself being able to connect somewhere else? Can you give us the exact error message, with any traceback, etc., context?
You say there are many APIs (assuming API servers) on the machine and only some fail (assuming you tested this from the machine that is having problems connecting to the API server machine).
Are the working servers on different ports compared to the non-working ones?
Do those servers work from within the network? You say they're working fine outside of it. (It's possible that your local network has a firewall policy that prohibits this local connection.)
Can you double-check that the non-working servers are actually running? (An easy way to establish this would be running ss -ltpn; it should give you a list of listening TCP ports and their associated processes.)
I have a client web application (A) who tries to get the information of another application (B) with a webservice.
I've been testing it in my local machine and all went like a charm. However, when I uploaded them to my server (CentOS 6, SELinux disabled, Firewall configuration checked) I get the following error:
wsdl error: Getting http://applicationB/?wsdl - HTTP ERROR: Couldn't open socket connection to server http://applicationB/?wsdl, Error (110): Connection timed out
Of course, "applicationB" is a valid URL.
They are in the same server. One is in appa.domain.com and the other one in appb.domain.com.
I've tried to call directly the IP of the server in stead of writing the domain name, but no luck with that neither.
If I check manually the WSDL URL, I get a well formatted WSDL file, so it's not the problem.
I've tried to connect external webservices and they work well, so I think it's a problem with having the server and client webservices in the same machine (or domain).
With that in mind, I've also tried to listen to port 81 and calling the webservice via this port, so the listening port and the requesting port would not be the same. No luck neither.
I'm stuck with this, and I cannot get more ideas to solve it or to find a workaround.
Anyone of you maybe have experienced this problem before and know how to solve it?
Thanks in advance for your time and answers!
EDIT
I've been trying to connect to my localhost webpage via command line, using Lynx browser from my server and I can't not access the page, even trying with its IP. It cannot be reached.
Maybe this could help to find out a solution.
Finally I got it working...
I post the answer here to be helpful for future users.
The problem was in the hosts server file. As #Amenadiel told me in a comment, it wasn't resolving the names.
I changed the hosts files and it seems it took more than I expected (I made the changes 3 days before and they weren't applied yet) so I discarded the hosts issues as an option. But it seems it was the only problem.
Why, then, didn't work neither when I tried to reach it using its IP? Well, it's because of the server nature. It's a server hosted in the Cloud, so it will be - for sure - a Virtual Machine.
It has a public IP (the one I was pointing to) and a private LAN IP. The server could not see the public IP, so if I was about to use one, it should have been the private (LAN) one.
Thanks again to all of you for your answers and your patience with this server side newbie!