use of com.neuronrobotics.sdk.network.BowlerTCPServer in project java-bowler by NeuronRobotics.
the class BowlerAbstractServer method startNetworkServer.
public void startNetworkServer(final int port) throws IOException {
udpServer = new BowlerUDPServer(port);
serverSocket = new ServerSocket(port + 1);
new Thread() {
public void run() {
setName("Bowler Platform Network Server");
addServer(udpServer);
while (true) {
Socket s;
try {
// ex.printStackTrace();
Log.warning("\n\nWaiting for UDP connection on port " + (port) + "...");
Log.warning("\n\nWaiting for TCP connection on port " + (port + 1) + "...");
s = serverSocket.accept();
addServer(new BowlerTCPServer(s));
Log.warning("Got a connection!");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}.start();
}
use of com.neuronrobotics.sdk.network.BowlerTCPServer in project java-bowler by NeuronRobotics.
the class BowlerAbstractServer method pushAsyncPacket.
public synchronized void pushAsyncPacket(BowlerDatagram data) {
localServers.clear();
for (int i = 0; i < servers.size(); i++) {
localServers.add(getServers().get(i));
}
for (int i = 0; i < servers.size(); i++) {
try {
boolean run = false;
if (localServers.get(i).getClass() == BowlerTCPServer.class) {
BowlerTCPServer b = (BowlerTCPServer) localServers.get(i);
if (b.isClientConnected()) {
run = true;
Log.info("TCP Bowler client ...OK!");
}
} else {
run = true;
}
if (localServers.get(i).getClass() != BowlerUDPServer.class) {
// System.out.println("Sending packet to "+getServers().get(i).getClass());
if (run && localServers.get(i).isConnected()) {
// Log.warning("ASYNC<<\r\n"+data );
String classString = localServers.get(i).getClass().toString();
localServers.get(i).sendAsync(data);
Log.info("Sent packet to " + classString);
}
} else {
try {
localServers.get(i).sendAsync(data);
} catch (NullPointerException ex) {
}
}
} catch (IndexOutOfBoundsException ie) {
ie.printStackTrace();
} catch (Exception e) {
try {
e.printStackTrace();
BowlerAbstractConnection abs = localServers.get(i);
Log.error("No client connected to this connection " + abs.getClass());
abs.disconnect();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
localServers.clear();
}
Aggregations