Check game server ping in a browser? - web-services

I've been researching around regarding the capabilities of having a client access a website and check their ping in a game (so far there seems to be no possible way using JS, however there may be a way with AJAX?). Without a website, the method to check ping would be using the command-line ping command to the server address through ICMP. Would it be possible to check the ping of a client to the game server with a website middle-man?
EDIT: If I do a php solution as described here: Pinging a server in php without the port?
could I do something like checking the ping of client to my website, then checking from my website to the game server and then predict the ping of the client?

You cannot really use ping command from js, but you can use AJAX call to some empty file on your server, to measure the response time:
var start = new Date().getTime();
$.ajax('http://your_server/empty_file')
.always(function( data ) {
console.log(new Date().getTime()-start);
});
EDIT: you can only 'ping' game server using this method if it has HTTP server running on it (you may need to set up headers to enable cross-domain requests for that). If both servers are on the same fast local network, there is no need to ping to both servers separately, the measurments are going to be the same.

Related

Can a remote server send response to a local client on a custom port?

For network gurus out there, I'll like to ask some questions regarding some unique setup where the server will be sending a request to a client on localhost on a certain port.
I have a cloudy understanding of some network fundamentals that I hope you'll be able to help me out.
Kindly check the image below:
Basically, there's a static website hosted in AWS s3 and at some point this website will send a request to https://localhost:8001.
I was expecting that it will connect to the nginx container listening on port 8001 in my local machine, but it results in 504 gateway error.
My questions are:
Is it possible for a remote server to directly send data to a client at a particular port by addressing it as localhost?
How is it possible for the static website to communicate to my local docker container?
Thanks in advance.
In the setup you show, in the context of a Web site, localhost isn't in your picture at all. It's the desktop machine running the end user's Web browser.
More generally, you show several boxes in your diagram – "local machine", "Docker VM", "individual container", "server in Amazon's data center" – and within each of these boxes, if they make an outbound request to localhost, it reaches back to itself.
You have two basic options here:
(1) Set up a separate (Route 53) DNS name for your back-end service, and use that https://backend.example.com/... host name in your front-end application.
(2) Set up an HTTP reverse proxy that forwards /, /assets, ... to S3, and /api to the back-end service. In your front-end application use only the HTTP path with no host name at all.
The second option is more work to set up, but once you've set it up, it's much easier to develop code for. Webpack has a similar "proxy the backend" option for day-to-day development. This setup means the front-end application itself doesn't care where it's running, and you don't need to rebuild the application if the URL changes (or an individual developer needs to run it on their local system).

How to use Postman to send request to another PC's server?

I have an Rest Api created on my destination PC. I can make post request to localhost using postman from same PC. but I want to send a post request to the localhost of another machine. What steps do i have to take to achieve this?
To do so, you need to have both pc on the same local network if you want to test locally.
Use the other PC's(where REST API is deployed) IP or hostname to hit the REST API request.

C++ socket.io client over tor service

I am trying to send socket requests in C++ to an onion link I am hosting with tor services and node.js. My node.js server is being hosted on port 8080.
When I try to send socket requests to localhost:8080, it works perfectly fine.
However, when I try to send them to my onion link, it does not work.
The library I am using to handle sockets is https://github.com/socketio/socket.io-client-cpp.
The C++ code:
sio::client h;
connection_listener l(h);
h.set_open_listener(std::bind(&connection_listener::on_connected, &l));
h.set_close_listener(std::bind(&connection_listener::on_close, &l,std::placeholders::_1));
h.set_fail_listener(std::bind(&connection_listener::on_fail, &l));
h.connect("http://myonionlink.onion:8080/");
// it fails to connect to the onion link, but works perfectly fine with http://localhost:8080/
Why is this not working for the onion link? Do onion links work differently in this case?
Is there any method I can use to achieve this?
I think problem in ".onion TLD is not in the Internet DNS root" from https://en.wikipedia.org/wiki/.onion, under the hood library performs attempt to resolve your URL in the raw IP address and fails on it because there is not appropriate record in DNS table.

communication between web host server and home server

I have a web application hosted on an external server. I would create a communication beetwen my home server and the web application.
I thought something like that:
my home server send its ip to the web application
the web application send data to the home server
my home server send back some data
I want to implemente a P2P communication between the WebApp and the home server
it would be bettere if the communication is encrypted
i dont want to use dynamic dns
Is there something to implement that?
There are several types of IP. It can be "grey" and "white".
"Grey" means that your computer can't be accesses through it.
"White" IP's can be accessed directly. Also there are dynamic IP's
that changes through the time. It all depends from the provider.
It's possible that you have "white dynamic" IP but it's pretty rare
for providers to do.
It's easier to connect to server because it
always have "white" permament IP.
TCP/IP already does most of the work. You just create tcp connection and it stays. You just think about sending data.
My suggestion for you is to create something like this:
Home server connects to WebApp
Home server requests some data and WebApp sends back data
Home server sends request containing data and server respondes that all is ok
So you have client-server model. And client always does only requests and server does only responses. And they do not switch. It's easier to maintain.
There is common technology of doing that and it includes encryption too.
You should use HTTPS protocol. Https will do all the encryption(and safely exchange keys too) you just worry about certificates(there are ways not to buy certificate but sign them by yourself. It's whole another topic)
So you will send https requests from your home server PC(client) and get responses from server(webApp).
As you write on Python you would find this answer helpful for you:
HTTPS request in Python

Port blocked creating web app on AWS

I'm trying to create a web app on AWS and I'm running into port issues. I would like to have multiple apps providing different services on different ports. I've created a website (on the same instance) to receive a text query and pass it to my app on port 3000. The app listening on 3000 is written in CherryPy.
We are using a VPN to provide security for the AWS instance. When logged into the VPN, everything works fine. The web page loads, the query returns the correct data. When I disconnect from the VPN, or someone else goes to the page, the page still loads, but queries to the service time out.
I've used netstat to make sure the service is listening but I'm not sure what could be blocking traffic. I've worked through the CORS issues as evident by the fact it works when I'm signed into the VPN.
What can I check now?
When I disconnect from the VPN, or someone else goes to the page, the page still loads, but queries to the service time out.
My assumption is that the web server and the app are on the same server.
It sounds very much like the connection from web server to app is happening via a routed IP address rather than localhost. In addition to being slower, it's also hitting your firewall rules.
Configure the web server to access your app on localhost:3000 and the issue should clear up.
I actually got it working. I have an AWS instance with nginix and CherryPy. When the user goes to a web address, the nginix page loads with a form for a query string. When they submit a string, the string is POSTed to a CherryPy service running on port 3000. The CherryPy service does some computations and returns a result via JSON.
I thought I had opened up everything completely for testing, but I was having so many issues. It turned out that having CherryPy set
"Access-Control-Allow-Origin" = "*"
wasn't working, instead I needed to specifically set the origin of the calling page.