How to detect Minecraft Singleplayer LAN port - javascript

Some Backstory
So I really need help with this project I am making that is suppose to try to find an open port from my Minecraft SinglePlayer LAN. As making something like that is easier then creating a server. To help with my project, I use this API https://mcapi.us/, which helps getting the status.
Firstly, I did try to use a for loop to loop through a huge range but with registering it through the API, it overloads my computer CPU. Secondly, I tried finding some help online and found about web workers and saw I could divide up work. It was about perfect but then seen that I cannot use the API (The most important part) on it as the elements that is in the API, web-workers cannot use.
The Problem:
So the problem is that I cannot properly range through a huge number like 10000 to 65535 as just running that through the API method overloads my CPU. I have also tried using PHP as well but no luck as it takes too long to read through all the numbers. I am probably going to have to use PHP though as it seems to be more powerful. But I need some way to get the Minecraft Singleplayer LAN port and I can't find any way to do that at all.
Reason:
The reason I need some way to access it is so I can make a web application to post the port the Minecraft Singleplayer LAN is running on and if offline will say another message. This way I can just send the web url to a friend and they can continuously just copy and paste the address and port for easy access so I don't have to keep sharing the port as that is non-efficient. One more thing as well, I am using Minecraft version that is before 1.13, not at 1.13 or after.
Question Update:
I have in fact made this question more clear to what I originally meant as what I said people was unclear so I updated this to be more clear. Plus Stack Overflow is kinda forcing me to make it more clear. So here, I hope this is clear for everyone.

Related

Duplicate websocket subscription in Azure webapp

I have a node.js app running in Azure as a webApp. On startup it connects to an external service using a websocket subscription. Specifically I'm using the reconnecting-websockets NPM package to wrap it to handle disconnects.
The problem I am having is that because there are 2 instances of the app running on Azure (horizontal scaling for failover) I end up with two subscriptions at any one time.
Is there an obvious way to solve this problem?
For extra context, this is a problem for 2 reasons:
I pay for each message received and am over quota
When messages are received I process then and do database updates, these are also being duplicated.
You basically want to have an AppService with potentially multiple instances, but you don't want your application to run in parallel. At least you don't want two have two subscriptions. Ideally you don't want to touch your application code.
An easy way to implement this would be to wrap your application into a continuous WebJob, and set its scale property to singleton.
Here is one tutorial on how to set up a nodejs webjob: https://morshemesh.medium.com/continuous-deployment-of-web-jobs-with-node-js-2308f95e63b1
You can then use a settings.job file to control that your webjob only runs on a single instance at any one time. Or you can use the Azure Portal to set the value when you manually deploy the Webjob.
{
"is_singleton": true
}
https://github.com/projectkudu/kudu/wiki/WebJobs-API#set-a-continuous-job-as-singleton
PS: Don't forget to enable Always On. It is also mentioned in the docs. But you probably already need that for your current deployment.
If you don't want your subscription to be duplicated then it stands to reason that you only want one process subscribing to the external websocket connection.
Since you mentioned that messages received will be updated in the db, then it makes sense that this would be an isolated backend process since you made it clear that you have multiple instances running for the frontend server (and whether or not a separate backend).
Of course if you want more redundancy, you could use a load balancer with simple distribution of messages to any number of instances behind. Perhaps some persistent queueing system if you feel that it's needed.
If you want these messages to be propagated to the client (not clear from the question), this will be a bit more annoying. If it's a one-way simple channel, then you could consider using SSE which is a rather simple protocol. If it's bilateral then I would myself probably consider running a STOMP server with intermediary broker (like RabbitMq) and connect directly from the client (i.e. the browser, not the server generating the frontend) to the service.
Not sure if you're well versed with Java, but I made some app that you could use for reference in case interested when we had to prepare some internal demos: https://github.com/kimgysen/zwoop-backend/tree/develop/stomp-api/src/main/java/be/zwoop
For all intents and purposes, I'm not sure if all this is worth the hustle for you, it sounds like you're on a tight budget and that you're looking for simple solutions without too much complexity. Have you considered giving up on load balancing the website (is the load really that high?), I don't have enough background knowledge on your project to judge, I believe. But proper caching optimization and initially scaling vertically may be sufficient at the start (?).
Personally I would start simple and gradually increase complexity when needed.
I'm just throwing ideas at you, hopefully it is helpful in any way to have a few considerations.
Btw, I don't understand why other answers on this question were all deleted (?).

javascript + mysql live changes

I read several tutorials, but I couldn't find a working example for my case.
I want to have a live-refresh (side-wise), whenever there is a change on the database (lets say I'd change values via phpmyadmin).
From what I understood, socket.io should be one solution. Also, I found this tutorial here, but it seems outdated, so it doesn't work anymore (from what I can tell).
Are there any alternatives or working examples? It can be pretty basic, but using setInterval with a param in range of 100 - 500 seems a bit to heavy, right? I can't wait for more than 1 sec.
I'm not sure, if there are any listeners or service, which can "push" a change to a JS-site, so I wouldn't rely on the JavaScript timeout-function.
Also, from the docs (and examples) on socket.io, I found ways to run the server on localhost, but not on the server. Lets say, I have this:
var.app = require('http').createServer(handler),
...
app.listen(8000);
it seems to listen to localhost:8000. Can I just replace this param to a live-url?
You could use WebSockets, it's already widely supported, but you still need to have a WebSockets server running on your machine, you still would NOT be able to actually send changes that you have made in phpmyadmin, because PHP does not know if you made any changes there.
The solution would be really complicated probably, because you would have to combine options, most of the stuff you could probably solve with WebSockets, so you would just send notifications from PHP to JavaScript, but apart from that, you would also have to check the database for changes, if you really wanted to monitor changes by you in phpmyadmin ( which I strongly advise against, it is easier, to create functions that modify the database in a way that you want, then to check the database every some ms ).
Your structure would probably look something like:
JavaScript -> connects to -> PHP WebSockets server
and on every change you submit the change to JavaScript.
Sorry, I cannot help you on setting the WebSockets server, but I know that Symfony2 has a package for it, you could go download and reverse-engineer it.
Here's the MDN page: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API

jQuery alternatives for multiplayer games?

First off, I am not asking for any code or anything like that.
all I need is some advise.
I'm creating a roulette game and everything in my roulette game is based on jQuery.
however, as we all know, jQuery is client side so I was thinking about using AJAX to send some details back to server and from the server to the users browser so I can make this roulette game work in "multiplayer" fashion... But the issue is that I don't think its possible to send the roulette's wheel animation to the server and back to users browser so I am a bit confused about this!
In my research I came across some information (old ones) about using node.js and jquery together! I don't know if this is possible or how easy it would be to use my jquery code in node.js as I have never used node.js before..
so the question that i have is:
based on the information i provided above and my requirements, what are my options?
can I use AJAX to achieve what i am trying to do and if so, a bit
information would be great.
if AJAX is out of question, is it possible to use my jquery code in
node.js to achieve what I am trying to do?
ANY ADVISE WOULD BE APPRECIATED.
P.S. I don't want to use HTML5 as 1st I don't know much about HTML5 and also, some devices, browsers do not support it.
Thanks
The best way is to use websockets to ensure real time communication. One of the best alternatives for implementing that could be using a server under node.js. Have a look to this video from Code School node.js tutorials: https://www.youtube.com/watch?v=mtDK4jf4RS0 where is ilustrated how to implement a real time chat. Your problem is based on the same.
There are three parts to a multiplayer game displayed in a browser:
client-side display,
server-side data management,
client-server communication.
If you're already set on your display technology (jQuery), then you're probably going to use $.ajax() for client-server communication. However, technologies used for server-side data management are completely up to you and they don't necessarily have any connection to the technologies used for display and communication (meaning the traditional communication initiated by client).
Basically, use any kind of server technology stack you like. Node.js might do just fine but there are many other viable alternatives. They just need to support communication with the client.
So, to be absolutely clear, your question doesn't really make sense. You might use jQuery in the client and Node.js on the server, but they will never really "work together". They will manage completely separate parts of your application and connect through protocols not specific to either of them.
As for the animation, the animation itself is solely a client-side problem. If you want to "synchronize the animation" across multiple clients, you can let the clients communicate with the server, but they only ever need to send/receive plain data. Then you adjust the client-side animation based on the received data.
As another poster points out, websockets are a better fit for this than regular client-initiated HTTP requests. Not because of "the animation", but because you want all the clients to receive the information about the start of betting at the same time.
I am also developing a MMO game using javascript only. Firstly, there are two different types of javascript here. Usual client side javascript (the one you already know) and the server side javascript (i.e. Node.js).
You will need to develop both client and server before connecting them with jQuery's Ajax. So you need to study Node.js before designing overall architecture of your game.
I read many Node.js tutorials and watched many youtube tutorial videos but I was still confused, before I really sat down and read a good textbook that explained from basics, one like below. Try to get hold of it from your local library.
Express web application development learn how to develop web applications with the Express framework from scratch by Hage Yaapa
Express is the popular framework that runs on Node.js now. So it's worth getting familiar with Express Framework. Once you understand how express app works (not so difficult), you will see how you can frame your game structure like I did :)
In order for many clients to share same animation, there must a server that synchronizes the game state. Ajax can only link between server-client communication in my understanding. There is no mechanism that connects between clients. The clients ask server what number was the result of roulette roll and show the corresponding animations.
Yes, you can use NodeJS and jQuery together.
NodeJS is server-side, meaning that you set up a server (a lot of people use the Express module, which is easy to use), which serves content to clients asking for it. Your server-side code can be in any language supporting sockets, not just NodeJS. But NodeJS is easy to use if you know JS already.
jQuery is client-side, meaning that it's executed by the user's browser, and may or may not have a server-side component (if it doesn't need it), or it might have one where it sends requests to the server-side code. When it requests a page from the server, it can be static content (like when you request index.html) or dynamic via an AJAX request. Client-side browser code must be HTML/CSS/JS (you can't make Firefox or Chrome interpret C, for example).

Can I create a listener in JS instead of repeatedly requesting a URL?

I'm working on a tool that will require 'listening' for a response from the server.
Currently I've got the page using JQuery to request a URL and respond based on it's output.
I do that every couple seconds.
However, as there will likely be hundreds of people using the tool all at the same time, that could be a pretty big server load.
Is there a way I can create a 'listener' that will notify the loaded pages when a change happens instead of constantly querying the server?
I haven't really been able to find much on Google (probably not searching for the correct thing) so hopefully someone here will know exactly what I'm talking about.
Thanks in advance for your quick responses!
You are looking for technologies named Comet or server push. There are several different implementations of this problem, typically involving long-running, but idle HTTP connections. Check out Atmosphere (in Java) or various other libraries.
Also make sure to have a look at web sockets (new HTML5 technology).
See also
COMET javascript library

Is there anyway to do port discover from Javascript in an intranet web application?

Say I wanted to write a local web server that listened on a random port.
Now I want to write HTML that works in most browsers that can do AJAX calls to it.
Is there any fundamental limitation here?
EDIT: I've confused people - probably because this is almost the first time I've ever posted with the javascript tag and I don't have a feel for how to ask questions.
I recently became aware of node.js - which I didn't learn more than it makes writing stand alone web servers easy to implement.
Then I had the vision of a site sort of like this one (any programming board really) but where code samples could execute on end users local machine. I don't like browser plugins at all though, so I started trying to think of a way to make it happen with minimal knowledge between the web/browser part and the local machine's service (there has to be interaction - i just wanted to think of the minimal amount).
And that is just an example - really I write intranet business apps for a living (in which case defining well known ports is easier so I don't need an answer to this question for that purpose..)
The same origin policy will prevent you from accessing other ports (at least in most browsers), but you I guess you could send JSONP requests to every port on localhost, and then catch the port that gives a valid response.
...If you really wanted to, that is. There is a lot of valid ports, so it could take some time.

Categories

Resources