I am developing a network application that exchanges xml data from an android app to a remote server. The server receives xml requests from the apps, processes them, and returns an xml result.
My goal is to overcome the technical hurdles by establishing a simple proof-of-concept server and app pair that can talk to each other through a TCP socket connection.
I have Windows 7 operating with IIS that has a server on port 23 that receives an xml request, displays the request for me to see (on a memo field), and responds with a string back to the client. I know this server works (written with Delphi) because I have a delphi client that sends an xml request that gets displayed, and receives the output xml from the server that it, in turn, displays.
I wish to create an andoid app using Eclipse that duplicates the client functionality - namely, it opens a socket connection with the server, sends pre-set xml (just a string) and receives the resulting xml from the server. I can’t even get the connection to work. I am new to android development so please bear with me. I will provide you with whatever you need to help.
Here is the android manifest:
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.example.client"
- android:versionCode="1"
- android:versionName="1.0" >
- <uses-sdk android:minSdkVersion="15" />
- <uses-permission android:name="android.permission.INTERNET" />
- <application
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name" >
- <activity
- android:name=".ClientTestActivity"
- 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>
- </manifest>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4
Here is the Java Code:
Using java Syntax Highlighting
- package com.example.client;
- import java.io.IOException;
- import java.net.InetSocketAddress;
- import java.net.Socket;
- import java.net.SocketAddress;
- import android.app.Activity;
- import android.os.Bundle;
- import android.widget.TextView;
- public class ClientTestActivity extends Activity {
- // Define our variables
- SocketAddress sockaddr; // Our socket address
- Socket my_socket; // Our Socket to send xml data
- TextView display_txt; // The display view we use to communicate results
- /** Called when the activity is first created. */
- [syntax="java"][/syntax] @Override
- public void onCreate(Bundle savedInstanceState) {
- /** Default constructors */
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- display_txt = (TextView)findViewById(R.id.textView1);
- /** Protect against exceptions */
- try {
- /** define the socket address. 10.0.2.2 should map to "Localhost" */
- SocketAddress sockaddr = new InetSocketAddress("10.0.2.2", 23);
- /** Instantiate and connect the socket */
- my_socket = new Socket();
- my_socket.connect( sockaddr );
- } catch (IOException e) {
- /** Report an exception encountered */
- display_txt.setText("Nasty Error");
- } finally {
- /** Catch any exception thrown from closing the socket */
- try {
- /** Close our socket and report results */
- my_socket.close();
- display_txt.setText("Connected Okay!");
- } catch (IOException e) {
- /** Display the error trying to close */
- display_txt.setText("Could not close socket.");
- }
- }
- }
- }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
When I run the app, I don't get the expected error messages or "Connected Okay!". I simply get the emulator stating "Unfortunately, Client_Socket has stopped".
Thank you VERY MUCH, in advance, for your time and help.
Scott


