add mpdroid & broadcast_mpd
BIN
1_6.h12_dev/broadcast_mpd/SocketAutoConnectClient.rar
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="src" path="gen"/>
|
||||||
|
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||||
|
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||||
|
<classpathentry kind="output" path="bin/classes"/>
|
||||||
|
</classpath>
|
@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>SocketAutoConnectClient</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.socketautoconnect.client"
|
||||||
|
android:versionCode="1"
|
||||||
|
android:versionName="1.0" >
|
||||||
|
|
||||||
|
<uses-sdk android:minSdkVersion="7" />
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:icon="@drawable/ic_launcher"
|
||||||
|
android:label="@string/app_name" >
|
||||||
|
<activity
|
||||||
|
android:name=".SocketAutoConnectClient"
|
||||||
|
android:label="@string/app_name" >
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" ></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" ></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" ></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" ></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.WAKE_LOCK" ></uses-permission>
|
||||||
|
</manifest>
|
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 2.1 KiB |
@ -0,0 +1,26 @@
|
|||||||
|
/* AUTO-GENERATED FILE. DO NOT MODIFY.
|
||||||
|
*
|
||||||
|
* This class was automatically generated by the
|
||||||
|
* aapt tool from the resource data it found. It
|
||||||
|
* should not be modified by hand.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.socketautoconnect.client;
|
||||||
|
|
||||||
|
public final class R {
|
||||||
|
public static final class attr {
|
||||||
|
}
|
||||||
|
public static final class drawable {
|
||||||
|
public static final int ic_launcher=0x7f020000;
|
||||||
|
}
|
||||||
|
public static final class id {
|
||||||
|
public static final int ip_info=0x7f050000;
|
||||||
|
}
|
||||||
|
public static final class layout {
|
||||||
|
public static final int main=0x7f030000;
|
||||||
|
}
|
||||||
|
public static final class string {
|
||||||
|
public static final int app_name=0x7f040001;
|
||||||
|
public static final int hello=0x7f040000;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
-optimizationpasses 5
|
||||||
|
-dontusemixedcaseclassnames
|
||||||
|
-dontskipnonpubliclibraryclasses
|
||||||
|
-dontpreverify
|
||||||
|
-verbose
|
||||||
|
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
|
||||||
|
|
||||||
|
-keep public class * extends android.app.Activity
|
||||||
|
-keep public class * extends android.app.Application
|
||||||
|
-keep public class * extends android.app.Service
|
||||||
|
-keep public class * extends android.content.BroadcastReceiver
|
||||||
|
-keep public class * extends android.content.ContentProvider
|
||||||
|
-keep public class * extends android.app.backup.BackupAgentHelper
|
||||||
|
-keep public class * extends android.preference.Preference
|
||||||
|
-keep public class com.android.vending.licensing.ILicensingService
|
||||||
|
|
||||||
|
-keepclasseswithmembernames class * {
|
||||||
|
native <methods>;
|
||||||
|
}
|
||||||
|
|
||||||
|
-keepclasseswithmembers class * {
|
||||||
|
public <init>(android.content.Context, android.util.AttributeSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
-keepclasseswithmembers class * {
|
||||||
|
public <init>(android.content.Context, android.util.AttributeSet, int);
|
||||||
|
}
|
||||||
|
|
||||||
|
-keepclassmembers class * extends android.app.Activity {
|
||||||
|
public void *(android.view.View);
|
||||||
|
}
|
||||||
|
|
||||||
|
-keepclassmembers enum * {
|
||||||
|
public static **[] values();
|
||||||
|
public static ** valueOf(java.lang.String);
|
||||||
|
}
|
||||||
|
|
||||||
|
-keep class * implements android.os.Parcelable {
|
||||||
|
public static final android.os.Parcelable$Creator *;
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
# This file is automatically generated by Android Tools.
|
||||||
|
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||||
|
#
|
||||||
|
# This file must be checked in Version Control Systems.
|
||||||
|
#
|
||||||
|
# To customize properties used by the Ant build system use,
|
||||||
|
# "ant.properties", and override values to adapt the script to your
|
||||||
|
# project structure.
|
||||||
|
|
||||||
|
# Project target.
|
||||||
|
target=android-7
|
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 2.5 KiB |
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/hello" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ip_info"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="20dip"
|
||||||
|
android:text="检测到服务端IP: " />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<string name="hello">Hello World, SocketAutoConnectClient!</string>
|
||||||
|
<string name="app_name">UDP Client</string>
|
||||||
|
|
||||||
|
</resources>
|
@ -0,0 +1,98 @@
|
|||||||
|
package com.socketautoconnect.client;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import java.net.DatagramPacket;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.MulticastSocket;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
public class SocketAutoConnectClient extends Activity implements Runnable
|
||||||
|
{
|
||||||
|
private MulticastSocket multicastSocket=null;
|
||||||
|
private static int BROADCAST_PORT=9898;
|
||||||
|
private static String BROADCAST_IP="224.0.0.1";
|
||||||
|
InetAddress inetAddress=null;
|
||||||
|
Thread thread=null;
|
||||||
|
TextView ipInfo;
|
||||||
|
private static String ip;
|
||||||
|
Handler myHandler=new Handler()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg)
|
||||||
|
{
|
||||||
|
super.handleMessage(msg);
|
||||||
|
if(msg.what==1)
|
||||||
|
{
|
||||||
|
ipInfo.append(msg.obj.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/** Called when the activity is first created. */
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.main);
|
||||||
|
ipInfo=(TextView) findViewById(R.id.ip_info);
|
||||||
|
thread=new Thread(this);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
multicastSocket = new MulticastSocket(BROADCAST_PORT);
|
||||||
|
inetAddress=InetAddress.getByName(BROADCAST_IP);
|
||||||
|
multicastSocket.joinGroup(inetAddress);
|
||||||
|
thread.start();
|
||||||
|
|
||||||
|
} catch (Exception e1)
|
||||||
|
{
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run( )
|
||||||
|
{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
Message msg=new Message();
|
||||||
|
msg.what=1;
|
||||||
|
byte buf[] = new byte[1024];
|
||||||
|
DatagramPacket dp =null;
|
||||||
|
dp=new DatagramPacket(buf,buf.length,inetAddress,BROADCAST_PORT);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
multicastSocket.receive(dp);
|
||||||
|
Thread.sleep(3000);
|
||||||
|
ip=new String(buf, 0, dp.getLength());
|
||||||
|
msg.obj=ip;
|
||||||
|
myHandler.sendMessage(msg);
|
||||||
|
System.out.println("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP : "+ip);
|
||||||
|
// Toast.makeText(this, new String(buf, 0, dp.getLength()), Toast.LENGTH_SHORT);
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy()
|
||||||
|
{
|
||||||
|
super.onDestroy();
|
||||||
|
multicastSocket.close();
|
||||||
|
System.out.println("UDP Client<6E><74><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD>,<2C>ص<EFBFBD>socket,ֹͣ<CDA3>㲥");
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
BIN
1_6.h12_dev/broadcast_mpd/SocketAutoConnectServer.rar
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="src" path="gen"/>
|
||||||
|
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||||
|
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||||
|
<classpathentry kind="output" path="bin/classes"/>
|
||||||
|
</classpath>
|
@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>SocketAutoConnectServer</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.socketautoconnect.server"
|
||||||
|
android:versionCode="1"
|
||||||
|
android:versionName="1.0" >
|
||||||
|
|
||||||
|
<uses-sdk android:minSdkVersion="7" />
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:icon="@drawable/ic_launcher"
|
||||||
|
android:label="@string/app_name" >
|
||||||
|
<activity
|
||||||
|
android:name=".SocketAutoConnectServer"
|
||||||
|
android:label="@string/app_name" >
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" ></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" ></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" ></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" ></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.WAKE_LOCK" ></uses-permission>
|
||||||
|
</manifest>
|
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 2.1 KiB |
@ -0,0 +1,27 @@
|
|||||||
|
/* AUTO-GENERATED FILE. DO NOT MODIFY.
|
||||||
|
*
|
||||||
|
* This class was automatically generated by the
|
||||||
|
* aapt tool from the resource data it found. It
|
||||||
|
* should not be modified by hand.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.socketautoconnect.server;
|
||||||
|
|
||||||
|
public final class R {
|
||||||
|
public static final class attr {
|
||||||
|
}
|
||||||
|
public static final class drawable {
|
||||||
|
public static final int ic_launcher=0x7f020000;
|
||||||
|
}
|
||||||
|
public static final class id {
|
||||||
|
public static final int ip_info=0x7f050001;
|
||||||
|
public static final int sendUDPBrocast=0x7f050000;
|
||||||
|
}
|
||||||
|
public static final class layout {
|
||||||
|
public static final int main=0x7f030000;
|
||||||
|
}
|
||||||
|
public static final class string {
|
||||||
|
public static final int app_name=0x7f040001;
|
||||||
|
public static final int hello=0x7f040000;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
-optimizationpasses 5
|
||||||
|
-dontusemixedcaseclassnames
|
||||||
|
-dontskipnonpubliclibraryclasses
|
||||||
|
-dontpreverify
|
||||||
|
-verbose
|
||||||
|
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
|
||||||
|
|
||||||
|
-keep public class * extends android.app.Activity
|
||||||
|
-keep public class * extends android.app.Application
|
||||||
|
-keep public class * extends android.app.Service
|
||||||
|
-keep public class * extends android.content.BroadcastReceiver
|
||||||
|
-keep public class * extends android.content.ContentProvider
|
||||||
|
-keep public class * extends android.app.backup.BackupAgentHelper
|
||||||
|
-keep public class * extends android.preference.Preference
|
||||||
|
-keep public class com.android.vending.licensing.ILicensingService
|
||||||
|
|
||||||
|
-keepclasseswithmembernames class * {
|
||||||
|
native <methods>;
|
||||||
|
}
|
||||||
|
|
||||||
|
-keepclasseswithmembers class * {
|
||||||
|
public <init>(android.content.Context, android.util.AttributeSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
-keepclasseswithmembers class * {
|
||||||
|
public <init>(android.content.Context, android.util.AttributeSet, int);
|
||||||
|
}
|
||||||
|
|
||||||
|
-keepclassmembers class * extends android.app.Activity {
|
||||||
|
public void *(android.view.View);
|
||||||
|
}
|
||||||
|
|
||||||
|
-keepclassmembers enum * {
|
||||||
|
public static **[] values();
|
||||||
|
public static ** valueOf(java.lang.String);
|
||||||
|
}
|
||||||
|
|
||||||
|
-keep class * implements android.os.Parcelable {
|
||||||
|
public static final android.os.Parcelable$Creator *;
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
# This file is automatically generated by Android Tools.
|
||||||
|
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||||
|
#
|
||||||
|
# This file must be checked in Version Control Systems.
|
||||||
|
#
|
||||||
|
# To customize properties used by the Ant build system use,
|
||||||
|
# "ant.properties", and override values to adapt the script to your
|
||||||
|
# project structure.
|
||||||
|
|
||||||
|
# Project target.
|
||||||
|
target=android-7
|
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 2.5 KiB |
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/hello" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/sendUDPBrocast"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="停止广播"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ip_info"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="20dip"
|
||||||
|
android:text="服务端自身IP: " />
|
||||||
|
|
||||||
|
"
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<string name="hello">Hello World, SocketAutoConnectClient!</string>
|
||||||
|
<string name="app_name">UDP Server</string>
|
||||||
|
|
||||||
|
</resources>
|
@ -0,0 +1,134 @@
|
|||||||
|
package com.socketautoconnect.server;
|
||||||
|
|
||||||
|
import java.net.DatagramPacket;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.MulticastSocket;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.wifi.WifiInfo;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import java.lang.*;
|
||||||
|
|
||||||
|
|
||||||
|
public class SocketAutoConnectServer extends Activity implements Runnable
|
||||||
|
{
|
||||||
|
private static String ip; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ip
|
||||||
|
private static int BROADCAST_PORT=9898;
|
||||||
|
private static String BROADCAST_IP="224.0.0.1";
|
||||||
|
InetAddress inetAddress=null;
|
||||||
|
Thread t=null;
|
||||||
|
/*<2A><><EFBFBD>㲥<CDB9>˵<EFBFBD>socket*/
|
||||||
|
MulticastSocket multicastSocket=null;
|
||||||
|
/*<2A><><EFBFBD>㲥<CDB9>İ<EFBFBD>ť*/
|
||||||
|
private Button sendUDPBrocast;
|
||||||
|
private volatile boolean isRuning= true;
|
||||||
|
TextView ipInfo;
|
||||||
|
/** Called when the activity is first created. */
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.main);
|
||||||
|
ipInfo=(TextView) findViewById(R.id.ip_info);
|
||||||
|
sendUDPBrocast=(Button) findViewById(R.id.sendUDPBrocast);
|
||||||
|
sendUDPBrocast.setOnClickListener(new SendUDPBrocastListener());
|
||||||
|
//Wifi״̬<D7B4>ж<EFBFBD>
|
||||||
|
WifiManager wifiManager=(WifiManager) getSystemService (Context.WIFI_SERVICE);
|
||||||
|
if(wifiManager.isWifiEnabled())
|
||||||
|
{
|
||||||
|
WifiInfo wifiInfo=wifiManager.getConnectionInfo();
|
||||||
|
ip=getIpString(wifiInfo.getIpAddress());
|
||||||
|
ipInfo.append(ip);
|
||||||
|
System.out.println("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>wifi IP:"+ip);
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
inetAddress=InetAddress.getByName(BROADCAST_IP);
|
||||||
|
multicastSocket=new MulticastSocket(BROADCAST_PORT);
|
||||||
|
multicastSocket.setTimeToLive(1);
|
||||||
|
multicastSocket.joinGroup(inetAddress);
|
||||||
|
|
||||||
|
}catch(Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
}
|
||||||
|
t=new Thread(this);
|
||||||
|
t.start();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//<2F><><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>int<6E><74>ipת<70><D7AA>string<6E><67><EFBFBD><EFBFBD>
|
||||||
|
private String getIpString(int i)
|
||||||
|
{
|
||||||
|
return (i & 0xFF) + "." +((i >> 8) & 0xFF) + "."
|
||||||
|
+((i >> 16) & 0xFF) + "." +(i >> 24 & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class SendUDPBrocastListener implements OnClickListener
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v)
|
||||||
|
{
|
||||||
|
if(isRuning)
|
||||||
|
{
|
||||||
|
isRuning=false;
|
||||||
|
sendUDPBrocast.setText("<EFBFBD><EFBFBD><EFBFBD>㲥");
|
||||||
|
System.out.println("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣ<EFBFBD>㲥..");
|
||||||
|
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
isRuning=true;
|
||||||
|
sendUDPBrocast.setText("ֹͣ<EFBFBD>㲥");
|
||||||
|
System.out.println("<EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><EFBFBD>㲥..");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
|
||||||
|
//<2F><><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD>е<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>
|
||||||
|
DatagramPacket dataPacket = null;
|
||||||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<49><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>̬<EFBFBD><CCAC>ȡ<EFBFBD><C8A1>IP<49><50><EFBFBD><EFBFBD>ַ<EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFA3AC>ʵserver<65>˽<EFBFBD><CBBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD>Ҳ<EFBFBD>ܻ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<49><50>
|
||||||
|
byte[] data =ip.getBytes();
|
||||||
|
dataPacket = new DatagramPacket(data, data.length, inetAddress,BROADCAST_PORT);
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
if(isRuning)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
multicastSocket.send(dataPacket);
|
||||||
|
Thread.sleep(3000);
|
||||||
|
System.out.println("<EFBFBD>ٴη<EFBFBD><EFBFBD><EFBFBD>ip<EFBFBD><EFBFBD>ַ<EFBFBD>㲥:.....");
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy()
|
||||||
|
{
|
||||||
|
super.onDestroy();
|
||||||
|
isRuning=false;
|
||||||
|
multicastSocket.close();
|
||||||
|
System.out.println("UDP Server<65><72><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD>,<2C>ص<EFBFBD>socket,ֹͣ<CDA3>㲥");
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|