mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-19 19:13:03 +00:00
Improved NvMDNS coding
This commit is contained in:
parent
1abdefdc15
commit
960d3ac319
@ -35,10 +35,8 @@ or to a theme attribute in the form "<code>?[<i>package</i>:][<i>type</i>:]<i>na
|
|||||||
public static final int ic_launcher=0x7f020000;
|
public static final int ic_launcher=0x7f020000;
|
||||||
}
|
}
|
||||||
public static final class id {
|
public static final class id {
|
||||||
public static final int editText1=0x7f080002;
|
public static final int mDNSResultView=0x7f080000;
|
||||||
public static final int hostTextView=0x7f080000;
|
public static final int surfaceView=0x7f080001;
|
||||||
public static final int statusButton=0x7f080001;
|
|
||||||
public static final int surfaceView=0x7f080003;
|
|
||||||
}
|
}
|
||||||
public static final class layout {
|
public static final class layout {
|
||||||
public static final int activity_connection=0x7f030000;
|
public static final int activity_connection=0x7f030000;
|
||||||
|
@ -1,35 +1,19 @@
|
|||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="fill_parent"
|
||||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||||
android:paddingTop="@dimen/activity_vertical_margin"
|
android:paddingTop="@dimen/activity_vertical_margin"
|
||||||
tools:context=".Connection" >
|
tools:context=".Connection" >
|
||||||
|
|
||||||
<EditText
|
<ListView
|
||||||
android:id="@+id/hostTextView"
|
android:id="@+id/mDNSResultView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="fill_parent"
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_alignParentTop="true" >
|
||||||
android:layout_marginTop="60dp"
|
</ListView>
|
||||||
android:ems="10"
|
|
||||||
android:hint="255.255.255.255"
|
|
||||||
android:textSize="50dp" >
|
|
||||||
|
|
||||||
<requestFocus />
|
|
||||||
</EditText>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/statusButton"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_below="@+id/editText1"
|
|
||||||
android:layout_centerHorizontal="true"
|
|
||||||
android:layout_marginTop="131dp"
|
|
||||||
android:text="Start Streaming Steam!"
|
|
||||||
android:textSize="50dp" />
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
@ -2,6 +2,7 @@ package com.limelight;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import com.limelight.nvstream.NvmDNS;
|
import com.limelight.nvstream.NvmDNS;
|
||||||
@ -28,10 +29,6 @@ public class Connection extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -58,7 +55,7 @@ public class Connection extends Activity {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
NvmDNS dns = new NvmDNS();
|
NvmDNS dns = new NvmDNS();
|
||||||
dns.sendQueryAndWait();
|
dns.execute();
|
||||||
} catch (IOException e2) {
|
} catch (IOException e2) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e2.printStackTrace();
|
e2.printStackTrace();
|
||||||
@ -68,20 +65,20 @@ public class Connection extends Activity {
|
|||||||
setContentView(R.layout.activity_connection);
|
setContentView(R.layout.activity_connection);
|
||||||
|
|
||||||
|
|
||||||
this.statusButton = (Button) findViewById(R.id.statusButton);
|
// this.statusButton = (Button) findViewById(R.id.statusButton);
|
||||||
this.hostText = (TextView) findViewById(R.id.hostTextView);
|
// this.hostText = (TextView) findViewById(R.id.hostTextView);
|
||||||
|
|
||||||
prefs = getPreferences(0);
|
//prefs = getPreferences(0);
|
||||||
this.hostText.setText(prefs.getString(Connection.HOST_KEY, Connection.DEFAULT_HOST));
|
//this.hostText.setText(prefs.getString(Connection.HOST_KEY, Connection.DEFAULT_HOST));
|
||||||
|
|
||||||
this.statusButton.setOnClickListener(new OnClickListener() {
|
/*this.statusButton.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View arg0) {
|
public void onClick(View arg0) {
|
||||||
Intent intent = new Intent(Connection.this, Game.class);
|
Intent intent = new Intent(Connection.this, Game.class);
|
||||||
intent.putExtra("host", Connection.this.hostText.getText().toString());
|
intent.putExtra("host", Connection.this.hostText.getText().toString());
|
||||||
Connection.this.startActivity(intent);
|
Connection.this.startActivity(intent);
|
||||||
}
|
}
|
||||||
});
|
});*/
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,12 @@ package com.limelight.nvstream;
|
|||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class NvComputer {
|
public class NvComputer {
|
||||||
private String mDNSResponse;
|
private String mDNSResponse;
|
||||||
private InetAddress ipAddress;
|
private InetAddress ipAddress;
|
||||||
|
private String ipAddressString;
|
||||||
private int state;
|
private int state;
|
||||||
private int numOfApps;
|
private int numOfApps;
|
||||||
private String gpuType;
|
private String gpuType;
|
||||||
@ -18,9 +20,10 @@ public class NvComputer {
|
|||||||
private boolean isBusy;
|
private boolean isBusy;
|
||||||
|
|
||||||
|
|
||||||
public NvComputer(String mDNSResponse, InetAddress ipAddress, int state, int numOfApps, String gpuType, String mac, String uniqueID) {
|
public NvComputer(String mDNSResponse, InetAddress ipAddress, String ipAddressString, int state, int numOfApps, String gpuType, String mac, String uniqueID) {
|
||||||
this.mDNSResponse = mDNSResponse;
|
this.mDNSResponse = mDNSResponse;
|
||||||
this.ipAddress = ipAddress;
|
this.ipAddress = ipAddress;
|
||||||
|
this.ipAddressString = ipAddressString;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.numOfApps = numOfApps;
|
this.numOfApps = numOfApps;
|
||||||
this.gpuType = gpuType;
|
this.gpuType = gpuType;
|
||||||
@ -38,6 +41,10 @@ public class NvComputer {
|
|||||||
return this.ipAddress;
|
return this.ipAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getIpAddressString() {
|
||||||
|
return this.ipAddressString;
|
||||||
|
}
|
||||||
|
|
||||||
public String getIPAddressString() {
|
public String getIPAddressString() {
|
||||||
return this.ipAddress.getCanonicalHostName().toLowerCase();
|
return this.ipAddress.getCanonicalHostName().toLowerCase();
|
||||||
}
|
}
|
||||||
@ -93,27 +100,27 @@ public class NvComputer {
|
|||||||
if (this.ipAddress == null) {
|
if (this.ipAddress == null) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
return this.ipAddress.getCanonicalHostName().hashCode();
|
return this.ipAddressString.hashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder returnStringBuilder = new StringBuilder();
|
StringBuilder returnStringBuilder = new StringBuilder();
|
||||||
returnStringBuilder.append("NvComputer 0x");
|
returnStringBuilder.append("NvComputer 0x");
|
||||||
returnStringBuilder.append(Integer.toHexString(this.hashCode()).toUpperCase());
|
returnStringBuilder.append(Integer.toHexString(this.hashCode()).toUpperCase(Locale.getDefault()));
|
||||||
returnStringBuilder.append("\n\tmDNS Hostname: ");
|
returnStringBuilder.append("\n|- mDNS Hostname: ");
|
||||||
returnStringBuilder.append(this.mDNSResponse);
|
returnStringBuilder.append(this.mDNSResponse);
|
||||||
returnStringBuilder.append("\n\tIP Address: ");
|
returnStringBuilder.append("\n|- IP Address: ");
|
||||||
returnStringBuilder.append(this.ipAddress.toString());
|
returnStringBuilder.append(this.ipAddress.toString());
|
||||||
returnStringBuilder.append("\n\tComputer State: ");
|
returnStringBuilder.append("\n|- Computer State: ");
|
||||||
returnStringBuilder.append(this.state);
|
returnStringBuilder.append(this.state);
|
||||||
returnStringBuilder.append("\n\tNumber of Apps: ");
|
returnStringBuilder.append("\n|- Number of Apps: ");
|
||||||
returnStringBuilder.append(this.numOfApps);
|
returnStringBuilder.append(this.numOfApps);
|
||||||
returnStringBuilder.append("\n\tGPU: ");
|
returnStringBuilder.append("\n|- GPU: ");
|
||||||
returnStringBuilder.append(this.gpuType);
|
returnStringBuilder.append(this.gpuType);
|
||||||
returnStringBuilder.append("\n\tMAC: ");
|
returnStringBuilder.append("\n|- MAC: ");
|
||||||
returnStringBuilder.append(this.mac);
|
returnStringBuilder.append(this.mac);
|
||||||
returnStringBuilder.append("\n\tUniqueID: ");
|
returnStringBuilder.append("\n\\- UniqueID: ");
|
||||||
returnStringBuilder.append(this.uniqueID);
|
returnStringBuilder.append(this.uniqueID);
|
||||||
returnStringBuilder.append("\n");
|
returnStringBuilder.append("\n");
|
||||||
return returnStringBuilder.toString();
|
return returnStringBuilder.toString();
|
||||||
|
@ -22,6 +22,7 @@ import android.net.nsd.NsdManager;
|
|||||||
import android.net.nsd.NsdManager.DiscoveryListener;
|
import android.net.nsd.NsdManager.DiscoveryListener;
|
||||||
import android.net.nsd.NsdManager.ResolveListener;
|
import android.net.nsd.NsdManager.ResolveListener;
|
||||||
import android.net.nsd.NsdServiceInfo;
|
import android.net.nsd.NsdServiceInfo;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,7 +30,7 @@ import android.util.Log;
|
|||||||
* @author yetanothername
|
* @author yetanothername
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class NvmDNS implements Runnable {
|
public class NvmDNS extends AsyncTask<Void, Integer, Void> {
|
||||||
|
|
||||||
public static String NVSTREAM_MDNS_QUERY = "_nvstream._tcp.local.";
|
public static String NVSTREAM_MDNS_QUERY = "_nvstream._tcp.local.";
|
||||||
public static String NVSTREAM_MDNS_MULTICAST_GROUP = "224.0.0.251";
|
public static String NVSTREAM_MDNS_MULTICAST_GROUP = "224.0.0.251";
|
||||||
@ -70,13 +71,31 @@ public class NvmDNS implements Runnable {
|
|||||||
Log.v("NvmDNS", "Constructor exited");
|
Log.v("NvmDNS", "Constructor exited");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendQueryAndWait() {
|
private void makeFakeData() {
|
||||||
Thread socketThread = new Thread(this);
|
try {
|
||||||
socketThread.start();
|
this.nvstream_mdns_responses.add(new NvComputer("127.0.0.1",
|
||||||
|
InetAddress.getByName("127.0.0.1"),
|
||||||
|
InetAddress.getByName("127.0.0.1").getCanonicalHostName(),
|
||||||
|
0,
|
||||||
|
4,
|
||||||
|
"Intel(R) Extreme Graphics 3",
|
||||||
|
"DE:AD:BE:EF:CA:FE",
|
||||||
|
"foo"));
|
||||||
|
this.nvstream_mdns_responses.add(new NvComputer("10.0.2.15",
|
||||||
|
InetAddress.getByName("10.0.2.15"),
|
||||||
|
InetAddress.getByName("10.0.2.15").getCanonicalHostName(),
|
||||||
|
0,
|
||||||
|
5,
|
||||||
|
"Intel(R) Extreme Graphics 2",
|
||||||
|
"DE:AD:BE:EF:CA:FE",
|
||||||
|
"bar"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void sendQueryAndWait() {
|
||||||
public void run() {
|
this.makeFakeData();
|
||||||
try {
|
try {
|
||||||
Log.v("NvmDNS UDP Loop", "mDNS Loop Started");
|
Log.v("NvmDNS UDP Loop", "mDNS Loop Started");
|
||||||
|
|
||||||
@ -154,16 +173,56 @@ public class NvmDNS implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NvComputer computer = new NvComputer(responses[0].getName().toString(), packet.getAddress(), state, numOfApps, gpuType, mac, uniqueID);
|
packet.getAddress().getCanonicalHostName();
|
||||||
|
|
||||||
|
NvComputer computer = new NvComputer(responses[0].getName().toString(), packet.getAddress(), packet.getAddress().getCanonicalHostName(), state, numOfApps, gpuType, mac, uniqueID);
|
||||||
this.nvstream_mdns_responses.add(computer);
|
this.nvstream_mdns_responses.add(computer);
|
||||||
Log.v("NvmDNS NvComputer", computer.toString());
|
Log.v("NvmDNS NvComputer", computer.toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... thisParameterIsUseless) {
|
||||||
|
Log.v("NvmDNS", "doInBackground init");
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Log.v("NvmDNS 1000 mS Wait", "going to sleep");
|
||||||
|
try {
|
||||||
|
|
||||||
|
Thread.sleep(5000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
Log.v("NvmDNS 1000 mS Wait", "waking from sleep");
|
||||||
|
NvmDNS.this.nvstream_socket.close();
|
||||||
|
NvmDNS.this.nvstream_socket = null;
|
||||||
|
Log.v("NvmDNS 1000 mS Wait", "socket closed");
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
|
||||||
|
this.sendQueryAndWait();
|
||||||
|
Log.v("NvmDNS", "doInBackground return");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onProgressUpdate(Integer... progress) {
|
||||||
|
Log.v("NvmDNS", "onProgressUpdate ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void moreUselessParameters) {
|
||||||
|
Log.v("NvmDNS", "onPostExecute");
|
||||||
|
for (NvComputer computer : this.nvstream_mdns_responses) {
|
||||||
|
Log.i("NvmDNS NvComputer Printout", computer.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user