Android Open Source - expo-connect I P Address Receiver






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;
/*w  w w.j  a  v a2  s . com*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.util.Log;

public class IPAddressReceiver {
  
  private ReceiverTask task = new ReceiverTask(); 
  private ConnectService context;
  
  
  public IPAddressReceiver(ConnectService context) {
    super();
    this.context = context;
  }

  public void receiveData(){
    
    task.execute();
    
  }
  
  public class ReceiverTask extends AsyncTask<Void, Void, String> {

    @Override
    protected String doInBackground(Void... params) {
      
      try {
        
        ServerSocket serverSocket = new ServerSocket(7777);
        Socket client = serverSocket.accept();

        Log.d(ConnectService.TAG, "Reading client ip address");
        InputStream inputstream = client.getInputStream();
              InputStreamReader ir = new InputStreamReader(inputstream);
              BufferedReader br = new BufferedReader(ir, 8*1024);
              
              String inputLine;
              StringBuilder sb = new StringBuilder();
              while((inputLine = br.readLine()) != null)
                sb.append(inputLine);
              br.close();   
              
              inputstream.close();
        serverSocket.close();
        
        Log.d(ConnectService.TAG, "Received ip: " + client.getInetAddress().toString());
        context.addPeerAddress(client.getInetAddress());
        return client.getInetAddress().toString();
        
      } catch (IOException e) {
        e.printStackTrace();
      }
      return "";
    }

    @Override
    protected void onPostExecute(String receivedIP) {
      Log.d(ConnectService.TAG, "IP address received: " + receivedIP);
    }
    
    
  }
}




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