Exemple #1
0
 @Override
 public boolean send(String message) {
   if (!socket.isConnected()) return false;
   try {
     output.writeUTF(message);
     Logger.i(this, "has send string " + message.length());
   } catch (IOException e) {
     Logger.printException(this, e);
     return false;
   }
   return true;
 }
Exemple #2
0
 @Override
 public boolean connect(String host, int port) {
   initSocket();
   if (socket.isConnected()) return false;
   try {
     socket.connect(new InetSocketAddress(host, port), Config.SOCKET_TIMEOUT);
     input = new DataInputStream(socket.getInputStream());
     output = new DataOutputStream(socket.getOutputStream());
   } catch (ConnectException e) {
     Logger.i(this, "Connection refused...");
   } catch (java.net.SocketTimeoutException e) {
     Logger.e(this, "Socket Timout!");
   } catch (IOException e) {
     Logger.printException(this, e);
   }
   return socket.isConnected();
 }
Exemple #3
0
  @Override
  public boolean send(byte[] message, int length) throws SocketException {
    if (!socket.isConnected()) return false;

    try {

      BinaryConverter.writeIntToBytes(length, lengthbytes);
      output.write(lengthbytes);
      output.write(message, 0, length);
      // Logger.i(this, "has send bytes " + (temp.length));
    } catch (SocketException e) {
      Logger.toast(this, "Connection lost, returning to Menu.");
      throw e;
    } catch (IOException e) {
      Logger.printException(this, e);
      return false;
    }
    return true;
  }
Exemple #4
0
 public TextureMapper(HashMap<String, float[]> textureCoords, Bitmap tileMap) {
   Logger.i(this, "Generated Tile Map " + tileMap.getWidth() + "x" + tileMap.getHeight());
   /*for(Entry<String, float[]> e : textureCoords.entrySet()){
   	Logger.i(this, e.getKey());
   	for(float f : e.getValue()){
   		Logger.i(this, "   "+f);
   	}
   }*/
   this.textureCoordLookup = textureCoords;
   this.bitmap = tileMap;
 }
Exemple #5
0
 @Override
 public boolean disconnect() {
   if (!socket.isConnected()) return false;
   try {
     input.close();
     output.close();
     socket.close();
   } catch (IOException e) {
     Logger.printException(this, e);
   }
   return !socket.isConnected();
 }
Exemple #6
0
 public void initSocket() {
   socket = new Socket();
   try {
     socket.setSendBufferSize(Config.SOCKET_MAX_SEND_BUFFER_SIZE);
     socket.setReceiveBufferSize(Config.SOCKET_MAX_RECEIVE_BUFFER_SIZE);
     socket.setKeepAlive(Config.SOCKET_KEEP_ALIVE_ENABLED);
     socket.setTcpNoDelay(Config.SOCKET_TCP_NO_DELAY);
     socket.setReuseAddress(true);
   } catch (SocketException e) {
     Logger.printException(this, e);
   }
 }
Exemple #7
0
 public void setLoaded(boolean loaded) {
   this.loaded = loaded;
   Logger.i(this, "TextureMapper has been Loaded to Graphics Memory");
 }