Why My Server don't receive data from Android client?

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Why My Server don't receive data from Android client?

Postby ANDev » Fri Dec 19, 2008 8:57 am

Server:

import java.lang.*;
import java.io.*;
import java.net.*;

class Server {
public static void main(String args[]) {

try {
ServerSocket srvr = new ServerSocket(4444);
System.out.print("Server Running!\n");
while(true){

Socket skt = srvr.accept();
System.out.print("Server has connected!\n");

BufferedReader in = new BufferedReader(new
InputStreamReader(skt.getInputStream()));

while (!in.ready()) {}
System.out.println(in.readLine());
System.out.println("\n");


skt.close();
in.close();
}
}
catch(Exception e) {
System.out.print("Whoops! It didn't work!\n");
}
}
}


Android Client:

package com.and.AndServer;

import java.io.PrintWriter;
import java.net.Socket;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import java.net.*;
import java.io.*;


public class AndServer extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
try{
connectSocket();
setContentView(R.layout.main);

}
catch(Exception e)
{


}


}

public void connectSocket()
{

try{
InetAddress serverAddr = InetAddress.getByName("MYPCIP");
Socket socket = new Socket(serverAddr, 4444);
PrintWriter out = new PrintWriter(socket.getOutputStream(),true);

out.print("Sending from Android Client");
out.close();
socket.close();

}
catch(Exception e){


}
}
}

Menifest :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.and.AndServer"
android:versionCode="1"
android:versionName="1.0.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name="AndServer"
android:label="@string/app_name">

<uses-permission android:name="android.permission.INTERNET" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

But when I try from PC client it works.

PC client:

import java.lang.*;
import java.io.*;
import java.net.*;

class Client {
public static void main(String args[]) {
try {
Socket skt = new Socket("MYPCIP", 4444);

PrintWriter out = new PrintWriter(skt.getOutputStream(), true);
out.print("Sending from PC Client");
out.close();
skt.close();

}


catch(Exception e) {
System.out.print("Whoops! It didn't work!\n");
}
}
}

I get the line "Sending from PC Client" in my Eclipse console when I run the PC client
but I see nothing when I try Android Client to run and I guess I am supposed to see "Sending from Android Client"

Can someone help?

Thanks.
--ANDev
ANDev
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Dec 15, 2008 2:39 am
Location: OR, USA

Top

Return to General

Who is online

Users browsing this forum: No registered users and 5 guests