3
activity_main.xml: //overover
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/app1"
android:layout_width="132dp"
android:layout_height="wrap_content"
android:text=" 发送APP1" />
<Button
android:id="@+id/app4"
android:layout_width="132dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textview"
android:layout_centerVertical="true"
android:text=" 发送APP4" />
<Button
android:id="@+id/app3"
android:layout_width="132dp"
android:layout_height="wrap_content"
android:layout_above="@+id/app4"
android:layout_alignLeft="@+id/app4"
android:layout_marginBottom="16dp"
android:text=" 发送APP3" />
<Button
android:id="@+id/app2"
android:layout_width="132dp"
android:layout_height="wrap_content"
android:layout_above="@+id/app3"
android:layout_alignLeft="@+id/app3"
android:layout_marginBottom="21dp"
android:text=" 发送APP2" />
<TextView
android:id="@+id/textview"
android:layout_width="132dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/app1"
android:layout_below="@+id/app4"
android:layout_marginTop="76dp" />
<TextView
android:layout_width="132dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/app4"
android:layout_below="@+id/app4"
android:layout_marginTop="26dp"
android:text="收到的显示是: " />
</RelativeLayout>
AndroidManifest.xml: //overover
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sockettest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.sockettest.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.example.sockettest.DataService" >
<intent-filter>
</intent-filter>
</service>
</application>
</manifest>