Im making an Android app that communicates with a server. When the Android-phone receives a SMS I want it to send it thru a socket to my server.
public class Server {
public static final int PORT = 8080;
public static void main(String[] args) throws IOException {
ServerSocket s = new ServerSocket(PORT);
try {
Socket socket = s.accept();
try {
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String str = in.readLine();
System.out.println(str);
}
finally {
socket.close();
}
}
finally {
s.close();
}
}
}
This is my client:
public Client(String message){
try {
Socket socket = new Socket("127.0.0.1", 8080);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
out.println(message);
socket.close();
}catch(Exception e){
e.printStackTrace();
}
}
Im not getting any connection when Im calling the Client class from the android app. Anyone know how to fix this problem?
The class 'Client' is called from the onReceive(Context context, Intent intent){ method when a message is received on the phone.