Allow network API to listen to specific host address
This commit is contained in:
parent
df34881771
commit
c5c6181e15
@ -1,14 +1,16 @@
|
|||||||
package fr.pandacube.lib.netapi.server;
|
package fr.pandacube.lib.netapi.server;
|
||||||
|
|
||||||
|
import fr.pandacube.lib.util.Log;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import fr.pandacube.lib.util.Log;
|
|
||||||
|
|
||||||
public class NetworkAPIListener implements Runnable {
|
public class NetworkAPIListener implements Runnable {
|
||||||
|
|
||||||
|
private final InetAddress host;
|
||||||
private final int port;
|
private final int port;
|
||||||
final String pass;
|
final String pass;
|
||||||
private ServerSocket serverSocket;
|
private ServerSocket serverSocket;
|
||||||
@ -16,30 +18,42 @@ public class NetworkAPIListener implements Runnable {
|
|||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instencie le côté serveur du NetworkAPI
|
* Instencie le côté serveur du NetworkAPI.
|
||||||
*
|
*
|
||||||
* @param n nom du networkAPI (permet l'identification dans les logs)
|
* @param n nom du networkAPI (permet l'identification dans les logs)
|
||||||
* @param p le port d'écoute
|
* @param p le port d'écoute
|
||||||
* @param pa le mot de passe réseau
|
* @param pa le mot de passe réseau
|
||||||
*/
|
*/
|
||||||
public NetworkAPIListener(String n, int p, String pa) {
|
public NetworkAPIListener(String n, int p, String pa) {
|
||||||
|
this(n, null, p, pa);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instencie le côté serveur du NetworkAPI.
|
||||||
|
*
|
||||||
|
* @param n nom du networkAPI (permet l'identification dans les logs)
|
||||||
|
* @param p le port d'écoute
|
||||||
|
* @param pa le mot de passe réseau
|
||||||
|
*/
|
||||||
|
public NetworkAPIListener(String n, InetAddress h, int p, String pa) {
|
||||||
|
name = n;
|
||||||
|
host = h;
|
||||||
port = p;
|
port = p;
|
||||||
pass = pa;
|
pass = pa;
|
||||||
name = n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
try {
|
try {
|
||||||
serverSocket = new ServerSocket(port);
|
serverSocket = host == null ? new ServerSocket(port) : new ServerSocket(port, 50, host);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println(e.getMessage());
|
System.err.println(e.getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.info("NetworkAPI '" + name + "' à l'écoute sur le port " + port);
|
Log.info("NetworkAPI '" + name + "' à l'écoute sur le socket " + serverSocket.getLocalSocketAddress());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// réception des connexion client
|
// réception des connexion client
|
||||||
|
Loading…
Reference in New Issue
Block a user