Compare commits
No commits in common. "1d3e56e9b7b73f2b0c4177116ce77a31e6679ccc" and "c50a2fb2516fbed930dcb13eddaff1d80b12bc5f" have entirely different histories.
1d3e56e9b7
...
c50a2fb251
5 changed files with 14 additions and 24 deletions
|
|
@ -54,7 +54,9 @@ public class ConnectionListener {
|
||||||
try {
|
try {
|
||||||
server = new ServerSocket(TCP_PORT);
|
server = new ServerSocket(TCP_PORT);
|
||||||
while (!shouldStop) {
|
while (!shouldStop) {
|
||||||
|
System.out.println("Accepting...");
|
||||||
Socket clientSocket = server.accept();
|
Socket clientSocket = server.accept();
|
||||||
|
System.out.println("New connection from " + clientSocket.getRemoteSocketAddress());
|
||||||
callback.onNewConnection(clientSocket);
|
callback.onNewConnection(clientSocket);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
||||||
|
|
@ -41,13 +41,4 @@ public class NetUtil {
|
||||||
}
|
}
|
||||||
return localList;
|
return localList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getIdFromIp(InetAddress ipAddr) {
|
|
||||||
byte[] addr = ipAddr.getAddress();
|
|
||||||
int id = 0;
|
|
||||||
for (byte b : addr) {
|
|
||||||
id = (id << 8) + b;
|
|
||||||
}
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,17 +100,9 @@ public class MainController implements Initializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startListening() {
|
|
||||||
if (userList != null) {
|
|
||||||
userList.startDiscoveryListening();
|
|
||||||
userList.startUserListening((e) ->
|
|
||||||
Log.e(this.getClass().getSimpleName(), "Error listening to users", e));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startChat() {
|
private void startChat() {
|
||||||
discoverActiveUsers();
|
discoverActiveUsers();
|
||||||
startListening();
|
userList.startDiscoveryListening();
|
||||||
Platform.runLater(this::showChat);
|
Platform.runLater(this::showChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,6 @@ import java.util.List;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
import static fr.insa.clavardator.network.NetUtil.getIdFromIp;
|
|
||||||
|
|
||||||
public class CurrentUser extends User {
|
public class CurrentUser extends User {
|
||||||
private static CurrentUser instance = null;
|
private static CurrentUser instance = null;
|
||||||
|
|
||||||
|
|
@ -33,11 +31,10 @@ public class CurrentUser extends User {
|
||||||
public void init() throws SocketException {
|
public void init() throws SocketException {
|
||||||
final List<InetAddress> addresses = NetUtil.listAllLocalAddresses();
|
final List<InetAddress> addresses = NetUtil.listAllLocalAddresses();
|
||||||
if (addresses.size() > 0) {
|
if (addresses.size() > 0) {
|
||||||
id = getIdFromIp(addresses.get(0));
|
id = addresses.get(0).hashCode();
|
||||||
} else {
|
} else {
|
||||||
throw new SocketException();
|
throw new SocketException();
|
||||||
}
|
}
|
||||||
setUsername("Moi2");
|
|
||||||
// TODO place by db username fetching
|
// TODO place by db username fetching
|
||||||
Timer t = new Timer();
|
Timer t = new Timer();
|
||||||
t.schedule(new TimerTask() {
|
t.schedule(new TimerTask() {
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,6 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import static fr.insa.clavardator.network.NetUtil.getIdFromIp;
|
|
||||||
|
|
||||||
public class UserList {
|
public class UserList {
|
||||||
|
|
||||||
private final Map<Integer, PeerUser> inactiveUsers = new HashMap<>();
|
private final Map<Integer, PeerUser> inactiveUsers = new HashMap<>();
|
||||||
|
|
@ -141,6 +139,16 @@ public class UserList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getIdFromIp(InetAddress ipAddr) {
|
||||||
|
byte[] addr = ipAddr.getAddress();
|
||||||
|
int id = 0;
|
||||||
|
for (byte b : addr) {
|
||||||
|
id = (id << 8) + b;
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addActiveUsersObserver(UserConnectionCallback connectionCallback, UserDisconnectionCallback disconnectionCallback) {
|
public void addActiveUsersObserver(UserConnectionCallback connectionCallback, UserDisconnectionCallback disconnectionCallback) {
|
||||||
userConnectionObservers.add(connectionCallback);
|
userConnectionObservers.add(connectionCallback);
|
||||||
userDisconnectionObservers.add(disconnectionCallback);
|
userDisconnectionObservers.add(disconnectionCallback);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue