예제 #1
0
  // we keep pointer to map object and grid object
  public MessageReader(SetUp grid) {

    conn = Connection.getInstance();
    messagelist = new ArrayList<>();
    this.grid = grid;
    conn.sendMessage("JOIN#");
  }
예제 #2
0
 @Override
 public void onOpen(Connection connection) {
   // To change body of implemented methods use File | Settings | File Templates.
   System.err.printf(
       "%s#onOpen %s %s\n",
       this.getClass().getSimpleName(), connection, connection.getProtocol());
   connectedClients.add(this);
   try {
     connection.sendMessage(publicher.getMessage().getMessage());
   } catch (IOException e) {
     e
         .printStackTrace(); // To change body of catch statement use File | Settings | File
                             // Templates.
   }
 }
 public void OnIncomingConnection(String device) {
   connectedDevice = device;
   if (isMaster) {
     Log.e("device connected", connectedDevice);
     mConnection.sendMessage(connectedDevice, "START");
     new Thread(new PositionSyncerThread()).start();
     try {
       Thread.sleep(400);
     } catch (InterruptedException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
     mVideo.start();
   }
 }
예제 #4
0
파일: WsSession.java 프로젝트: eldur/dt
  protected void send(String string) {
    if (!Strings.isNullOrEmpty(string)) {
      int textMessageLength = string.length();
      int maxTextMessageLength = connection.getMaxTextMessageSize();
      if (maxTextMessageLength > 0 && textMessageLength > maxTextMessageLength) {

        throw new IllegalStateException(
            "Too mutch text " + textMessageLength + " > " + maxTextMessageLength);
      }
      try {
        connection.sendMessage(string);
      } catch (IOException e) {
        throw new IllegalStateException(e);
      }
    }
  }
 /*
  * Handle websocket open a connection
  * (non-Javadoc)
  * @see org.eclipse.jetty.websocket.WebSocket#onOpen(org.eclipse.jetty.websocket.WebSocket.Connection)
  */
 @Override
 public void onOpen(Connection connection) {
   this.connection = connection;
   // this.connection.setMaxIdleTime(5*60*1000);
   this.connection.setMaxIdleTime(0);
   System.out.println("onOpen: " + connection + "|Time: " + new Date());
   try {
     connection.sendMessage("onOpen: " + connection);
     CopyOnWriteArrayList<CommunicationWebsocketBusiness> a =
         new CopyOnWriteArrayList<CommunicationWebsocketBusiness>();
     a.add(this);
     CommunicationWebsocketServlet.connections.put(connection.toString(), a);
   } catch (IOException e) {
     this.connection.close();
   } catch (Exception ex) {
     this.connection.close();
   }
 }
 public void OnMessageReceived(String device, String message) {
   if (message.indexOf("SYNC") == 0) {
     try {
       String[] syncMessageSplit = message.split(":");
       int diff = Integer.parseInt(syncMessageSplit[1]) - mVideo.getCurrentPosition();
       Log.e(
           "master - slave diff",
           Integer.parseInt(syncMessageSplit[1]) - mVideo.getCurrentPosition() + "");
       if ((Math.abs(diff) > 100) && (mVideo.getCurrentPosition() - lastSynced > 1000)) {
         mVideo.seekTo(mVideo.getCurrentPosition() + diff + 300);
         lastSynced = mVideo.getCurrentPosition() + diff + 300;
       }
     } catch (IllegalStateException e) {
       // Do nothing; this can happen as you are quitting the app
       // mid video
     }
     mConnection.sendMessage(connectedDevice, "ACK");
   } else if (message.indexOf("START") == 0) {
     Log.e("received start", "0");
     mVideo.start();
   } else if (message.indexOf("ACK") == 0) {
     canSend = true;
   }
 }