Android Open Source - expo-connect Screen Data Sender






From Project

Back to project page expo-connect.

License

The source code is released under:

GNU General Public License

If you think the Android project expo-connect 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 it.polimi.camparollo.expoconnectserver.wifi;
/*  ww  w. ja va  2  s .  c  om*/
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.ArrayList;

import android.os.AsyncTask;
import android.util.Log;


public class ScreenDataSender {

  private SenderTask task = new SenderTask(); 
  private ConnectService context;
  
  public ScreenDataSender(ConnectService context) {
    this.context = context;
  }
  
  public void sendData(ArrayList<String> data){
    
    task.execute(data);
    
  }

  public class SenderTask extends AsyncTask<ArrayList<String>, Void, Boolean> {

    @Override
    protected Boolean doInBackground(ArrayList<String>... params) {
      
      Socket socket = new Socket();
      
      try {
        
        String ipstr = params[0].get(0).split("/")[1];
        InetAddress host = InetAddress.getByName(ipstr);
        Log.d(ConnectService.TAG, host.toString());
        int port = 8888;
        int len;
        byte buf[]  = new byte[1024];
        
          /**
           * Create a client socket with the host,
           * port, and timeout information.
           */
          socket.bind(null);
          socket.connect(new InetSocketAddress(host, port), 10000);

          OutputStream outputStream = socket.getOutputStream();
          InputStream inputStream = new ByteArrayInputStream(params[0].get(1).getBytes());
          while ((len = inputStream.read(buf)) != -1) {
            Log.d(ConnectService.TAG, "sending:" + buf.toString());
              outputStream.write(buf, 0, len);
          }
          outputStream.close();
          inputStream.close();
          Log.d(ConnectService.TAG, "Data sent");
      } catch (Exception e) {
          e.printStackTrace();
      } finally {
          if (socket != null) {
              if (socket.isConnected()) {
                  try {
                      socket.close();
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
          }
      }
      return null;
    }
    
  }
}




Java Source Code List

it.polimi.camparollo.expoconnect.datatransfer.IPAddressSender.java
it.polimi.camparollo.expoconnect.datatransfer.RESTClient.java
it.polimi.camparollo.expoconnect.datatransfer.Restaurant.java
it.polimi.camparollo.expoconnect.datatransfer.ScreenDataReceiver.java
it.polimi.camparollo.expoconnect.exceptions.CannotEnableWifiP2pException.java
it.polimi.camparollo.expoconnect.recommendations.RestaurantListActivity.java
it.polimi.camparollo.expoconnect.recommendations.RestaurantListAdapter.java
it.polimi.camparollo.expoconnect.recommendations.SingleRestaurant.java
it.polimi.camparollo.expoconnect.uilisteners.ConnectionInfo.java
it.polimi.camparollo.expoconnect.uilisteners.PeersListUpdater.java
it.polimi.camparollo.expoconnect.utils.ScalingUtilities.java
it.polimi.camparollo.expoconnect.wifi.CustomWifiP2pManager.java
it.polimi.camparollo.expoconnect.wifi.InfoActionListener.java
it.polimi.camparollo.expoconnect.wifi.StartActivity.java
it.polimi.camparollo.expoconnect.wifi.WiFiDirectBroadcastReceiver.java
it.polimi.camparollo.expoconnectserver.CommandReceiver.java
it.polimi.camparollo.expoconnectserver.InfoActionListener.java
it.polimi.camparollo.expoconnectserver.ServiceStarterActivity.java
it.polimi.camparollo.expoconnectserver.uilisteners.ConnectionInfo.java
it.polimi.camparollo.expoconnectserver.uilisteners.PeersListUpdater.java
it.polimi.camparollo.expoconnectserver.wifi.ConnectService.java
it.polimi.camparollo.expoconnectserver.wifi.IPAddressReceiver.java
it.polimi.camparollo.expoconnectserver.wifi.ScreenDataSender.java
it.polimi.camparollo.expoconnectserver.wifi.WiFiDirectBroadcastReceiver.java