Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Lan Game list Ip addresses of Running Server
    primarykey
    data
    text
    <p>We are currently working on a client-server game in java. We used <code>DatagramSocket</code> to perform communications between client and server. Inorder for the client to communicate to server, he must know the LAN ip address of the machine where the server is running. Multiple clients can connect to server, we used a thread for each client.</p> <p>Our problem is we wanted to show a list of LAN ip addresses of running servers to the clients so that it is easier for them to find servers like slist command in Counter Strike. Our solution is the client sends a message to all computers connected to the network and if a computer with a running server receives it, it will reply a message back to the client and then we print it's ip address in the client. </p> <pre class="lang-java prettyprint-override"><code>InetAddress localHost = Inet4Address.getLocalHost(); String myIP=localHost.toString().substring(localHost.toString().lastIndexOf("/")+1); //split myIP into 4 parts (part1.part2.part3.part4) //use the first part to check the class of the network (A, B, or C) //I'll skip to C if(part1&gt;=1 &amp;&amp; part1&lt;=126) //A else if(part1&gt;=128 &amp;&amp; part1&lt;=191) //B else if(part1&gt;=192 &amp;&amp; part1&lt;=223){ String network= part1 + "." + part2 + "." part3; String guess; for(i=0;i&lt;255;i++){ guess = network+"."+i; serverSend(guess); //send the message to an ip address in the network } } </code></pre> <p>It works fine for network in class C but for B and A, it is too slow. We assume the worst-case subnet mask for B and A which is 255.255.0.0 (65,025 iterations) and 255.0.0.0 (16,581,375). </p> <p>Does anyone got a better solution to this? thank you in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload