Search in sources :

Example 1 with BowlerTCPServer

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();
}
Also used : BowlerUDPServer(com.neuronrobotics.sdk.network.BowlerUDPServer) BowlerTCPServer(com.neuronrobotics.sdk.network.BowlerTCPServer) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket)

Example 2 with BowlerTCPServer

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();
}
Also used : BowlerTCPServer(com.neuronrobotics.sdk.network.BowlerTCPServer) BowlerAbstractConnection(com.neuronrobotics.sdk.common.BowlerAbstractConnection) DeviceConnectionException(com.neuronrobotics.sdk.common.DeviceConnectionException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) RuntimeErrorException(javax.management.RuntimeErrorException)

Aggregations

BowlerTCPServer (com.neuronrobotics.sdk.network.BowlerTCPServer)2 IOException (java.io.IOException)2 BowlerAbstractConnection (com.neuronrobotics.sdk.common.BowlerAbstractConnection)1 DeviceConnectionException (com.neuronrobotics.sdk.common.DeviceConnectionException)1 BowlerUDPServer (com.neuronrobotics.sdk.network.BowlerUDPServer)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 UnknownHostException (java.net.UnknownHostException)1 RuntimeErrorException (javax.management.RuntimeErrorException)1