holy smokes what a mess

This commit is contained in:
Ben Fry
2014-11-14 16:48:07 -07:00
51 changed files with 685 additions and 457 deletions

View File

@@ -51,7 +51,6 @@ public class Client implements Runnable {
Thread thread;
Socket socket;
String ip;
int port;
String host;
@@ -274,7 +273,10 @@ public class Client implements Runnable {
* @brief Returns the IP address of the machine as a String
*/
public String ip() {
return socket.getInetAddress().getHostAddress();
if (socket != null){
return socket.getInetAddress().getHostAddress();
}
return null;
}

View File

@@ -178,6 +178,15 @@ public class Server implements Runnable {
}
/**
* Return true if this server is still active and hasn't run
* into any trouble.
*/
public boolean active() {
return thread != null;
}
static public String ip() {
try {
return InetAddress.getLocalHost().getHostAddress();
@@ -310,8 +319,8 @@ public class Server implements Runnable {
public void write(int data) { // will also cover char
int index = 0;
while (index < clientCount) {
clients[index].write(data);
if (clients[index].active()) {
clients[index].write(data);
index++;
} else {
removeIndex(index);
@@ -323,8 +332,8 @@ public class Server implements Runnable {
public void write(byte data[]) {
int index = 0;
while (index < clientCount) {
clients[index].write(data);
if (clients[index].active()) {
clients[index].write(data);
index++;
} else {
removeIndex(index);
@@ -336,8 +345,8 @@ public class Server implements Runnable {
public void write(String data) {
int index = 0;
while (index < clientCount) {
clients[index].write(data);
if (clients[index].active()) {
clients[index].write(data);
index++;
} else {
removeIndex(index);

View File

@@ -135,6 +135,15 @@ public class Serial implements SerialPortEventListener {
}
/**
* Return true if this port is still active and hasn't run
* into any trouble.
*/
public boolean active() {
return port.isOpened();
}
public void pre() {
if (serialAvailableMethod != null && invokeSerialAvailable) {
invokeSerialAvailable = false;