我有五个域服务器,我想在我的 android 应用程序中使用 java 套接字编程连接到该服务器。
这里我的服务器 "ANY1.g%%%%%%%%.dk" "ANY2.g%%%%%%%.dk" "ANY3.g%%%%%%%.dk" "ANY4 .g%%%%%%%%.dk" "ANY5.g%%%%%%%%.dk"
因此,当我在运行提示符下通过 ping 命令 ping 到任何服务器时,它工作正常并得到响应。
但是当我尝试使用此服务器创建套接字时,它给了我“未知主机”错误。
这是我的代码:
try
{
hostname = "ANY SERVER DOMAIN NAME";
port = ANY;
socket = new Socket(hostname, port);
socket.setReceiveBufferSize(2048);
socket.setKeepAlive(true);
Log.e("SOCKET",socket.isConnected());
}
catch(Exception e)
{
Log.e("ERROR",e.getMessage());
}
代码是否有任何问题或任何建议都会被接受?
清单文件:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.siliconithub.android.greencall"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_app_icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".GreenCall"
android:label="@string/title_activity_green_call"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".RecentCallActivity"
android:label="@string/title_activity_recentcall"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar" >
</activity>
<activity
android:name=".RecentCallDetailActivity"
android:label="@string/title_activity_recentcall_detail"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar" >
</activity>
<activity
android:name=".FavouritesActivity"
android:label="@string/title_activity_fovourites"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar" >
</activity>
<activity
android:name=".ContactsActivity"
android:label="@string/title_activity_contacts"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar" >
</activity>
<activity
android:name=".ContactDetailsActivity"
android:label="@string/title_activity_contactdetails"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar" >
</activity>
<activity
android:name=".TelnetServerActivity"
android:label="@string/title_activity_telnetserver"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar" >
</activity>
<activity
android:name=".SettingActivity"
android:label="@string/title_activity_setting"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black" >
</activity>
<activity
android:name=".SearchContactsActivity"
android:label="@string/title_activity_search_contacts"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar" >
</activity>
<service
android:name=".UpdateStatusService"
android:label="@string/title_service_update_status"
android:icon="@drawable/ic_app_icon"
android:enabled="true" />
<receiver android:name=".PhoneStateBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
</application>
</manifest>
谢谢你。