I recently started experimenting with TCP/IP in Java (question not Java specific), and I was wondering if there was a work-around to this problem: I want my Client to be able to list all available Local Network servers. This is easy when every server and client use the same port, eg. 48,000 - just cycle through every possible IP and ping any existing servers...
But what if a user already had a game open that was using port 48,000? The game would just crash with no work around. A fix would be for the server to loop and test every port between say 48,000 and 60,000, but then how would the client know which port to connect to?
I want to be able to list all available servers (like a game such as Halo does), without the user having to specify a port number.
Thanks for the help
Related
I am writing an app that is to be running on a Windows PC. I need to create a server socket listening on 127.0.0.1, and another client socket which is to connect with this server socket.
Since the data exchange between the two sockets are within the same machine and there is no client connecting from outside of the machine, what port to use is insignificant, as long as the two sockets use the same port number.
So, how do I decide which port number to use? Shall it be a hard-coded port number such as 49500? What if another unrelated app on this machine happen to use this port number? Or shall I get the list of all used ports and programmatically pick an unused port?
Just want to know what is the best approach. Thanks.
ports within 0 to 1023 are generally controlled and you should assign your socket with higher port numbers, although in that range ports within 1024 and 49151 can be registered for others to be informed about that and not use them.
if you want to avoid conflicts you can see registered ports on your machine and assign a port number to your socket which is empty but ports higher than that (49152 to 65535) are completely free and are not even registered.
generally, it is not common to worry about that. for example, two major applications like VMware and apache web server operate on the same port number (443), and if you want to use VMware workstation and Xampp (which works with apache) you have to simply make one of them listen on another port and its not a big deal. so in my opinion the best practice is to let your users change this via a config file or something similar.
for further information, you can search google. for instance this link might be useful:
https://www.sciencedirect.com/topics/computer-science/registered-port#:~:text=Well%2Dknown%20ports%E2%80%94Ports%20in,1023%20are%20assigned%20and%20controlled.&text=Registered%20ports%E2%80%94Ports%20in%20the,be%20registered%20to%20prevent%20duplication.&text=Dynamic%20ports%E2%80%94Ports%20in%20the,assigned%2C%20controlled%2C%20or%20registered.
I have one server and multiple clients. The server wants to run shell script on each device it wants to. Absolutely it's not possible via simple socket because we may have thousands of devices. Also server and devices should be always connected via socket. after a lot of search I found out that the solution might be NAT-T. But still I don't know how to use that or if there is another solution.
Please help me what should I do on clients and server.
If you don't know the clients address and port upfront, you need to connect to the server with the clients. 1000s of devices are no problem. You run in a socket limit around 65000 open ports (check ulimit). Build an object stream between client and server and execute the script based on the object the client receives. You could also set an interval on the clients and let them check with simple http(s) every n secs if there is something to do for them?
See for example here: Node Stream Docs
Or here: Node HTTP Docs
How to find, in python, server without having it's IP in LAN?
I assume that port will be configured in file so its doesn't have to find port. I tried to search on google but I couldn't find anything useful or that could help me with it.
The server IP will be changing because it will not run constantly on the same computer.
So basically I got app with server that is on random computer in network, and I want to find its IP from another computer.
I would be really thankful for either explanation how to do it or link that could help me to do it.
Not certain if this is what you want to do, I think you want to find the IP of a server by running some python execution on the server?
You could try :
from subprocess import call
call (["ipconfig"])
This will dump the IP config and you can parse out the IP address. This assumes a windows server. You would have to modify the call for your OS.
Updated :
Check this out : TCP Communications or UDP Communications ... it looks like what you are looking for. You will still have the mess of determining the available addresses on the network (arp -a), and testing each one - this would be your client side app. Your server side app, when it receives the right query on the TCP or UDP port, would then determine it's address (ipconfig) and return the value.
If I am running a local server that is hosting a video chat application what is the best way to test the application with another user? Lets say I have two computers, is there a way I can allow computer B to connect to the local server that is running on computer A? The goal is to simply test whether the video chat application works properly in two completely different browsers running on separate computers. If there is a way I can trick the app into thinking the computer that is running the local server is another host, please let me know.
But Remember that the app needs access to the computers webcam. Thanks!
Addition Info: Nodejs application that uses the Tokbox, express, and socket.io APIs
Just make sure your web server is listening on a routable IP like "0.0.0.0", which you specify when you call http.createServer(port, ip, handler). Then point the browsers at the server's IP address such as http://192.168.1.1:3000 (fill in your specific IP and port). You can use the command ifconfig -a on linux or osx to get your server's local IP address, and ipconfig on windows.
i want to add lan support to tic-tac-toe game which is a HTML5 canvas based, so that two players can easily play. how can i do it using javascript/node.js?
OK, I'm assuming all of your HTML5 game is finished and you're distributing it with the server that hosts it. (Otherwise you're stuck to just the browser, which can't do all the awesome node.js net stuff, I am describing.)
NB: You need to have node.js running on both clients. Otherwise you can't do LAN-only without a central server's involvement.
One of your clients has decided they want to host a LAN game
The node.js server running on that client starts to listen on a port
That server find out its local IP Get local IP address in node.js
Options:
Your players can manually tell each other the IP of the hosting server
Your hosting server sends out broadcast messages to its local subnet, informing them that it's hosting a game
Your other client server scans for IPs in its local subnet to find any hosting gameservers (Tries to open the pre-determined port your hosting server is listening on.)
The other node.js client opens a connection to the hosting server.
Done.