Android Open Source - Android-Wireless Sockets






From Project

Back to project page Android-Wireless.

License

The source code is released under:

MIT License

If you think the Android project Android-Wireless listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.Nimble.Server;
/*from  w  ww  .  j  a  va2s.  com*/
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import android.util.Log;

/**
 * Functions to read and write from sockets.
 * @author Michael Leith
 *
 */
public class Sockets {

  /**
   * 
   * @param socket
   * @param input
   */
  static public final void write(Socket socket, byte[] input)
  {  
    try{ write( socket.getOutputStream() , input ); }
    catch(Exception e) { Log.e("Write to Client", e.toString()); }
  }
  
  /**
   * 
   * @param outputStream
   * @param input
   */
  static public final void write(OutputStream outputStream, byte[] input)
  {
    try{
      outputStream.write(input);
      outputStream.flush();
    }
    catch(Exception e) { Log.e("Write to Client", e.toString()); }
  }
  
  /**
   * Reads all data currently in the provided InputStream.
   * @param inputStream
   * @return  A byte[] containing read data
   */
  static public final byte[] read(InputStream inputStream)
  {
    try{
      int numRead = 0, streamSize = inputStream.available();
      byte[] data = new byte[streamSize];
    
      while( streamSize - numRead > 0)
        numRead  += inputStream.read(data, numRead, streamSize-numRead);
      return data;
    }
    catch(Exception e)
    { Log.e("Read", e.getMessage()); }
    return null;
  }
  
  /**
   * Reads all data currently in the provided InputStream.
   * @param socket
   * @return A byte[] containing read data
   */
  static public final byte[] read(Socket socket)
  {
    try{
      InputStream s = socket.getInputStream(); //Should this be seperate??
      byte[] res = read(s);
      return res;
    }
    catch(Exception e)
    { Log.e("Read", e.getMessage()); }
    return null;
  }
}




Java Source Code List

com.Nimble.Server.ServerActivity.java
com.Nimble.Server.Server.java
com.Nimble.Server.Sockets.java
com.Nimble.WifiAP.ClientInfo.java
com.Nimble.WifiAP.ClientScanner.java
com.Nimble.WifiAP.HardwareStateManager.java
com.Nimble.WifiAP.MainWiFiAPActivity.java
com.Nimble.WifiAP.WifiAP.java
com.Nimble.WifiAP.scanActivity.java
generics.Methods.java
generics.testingSuite.java