Im a newbie to android. i want to create an application that sends the user1 location to the user2 using ServerSocket.
public class ToMain extends Activity {
TextView info, infoip, msg;
String message ="";
ServerSocket serverSocket;
String s="",t="";
public Double b,c;
public int i;
private class SocketServerThread extends Thread {
static final int SocketServerPORT = 8080;
int count = 0;
@Override
public void run() {
Socket socket = null;
DataInputStream dataInputStream = null;
DataOutputStream dataOutputStream = null;
try {
serverSocket = new ServerSocket(SocketServerPORT);
ToMain.this.runOnUiThread(new Runnable() {
@Override
public void run() {
info.setText("I'm waiting here: "
+ serverSocket.getLocalPort());
}
});
while (true) {
socket = serverSocket.accept();
dataInputStream = new DataInputStream(
socket.getInputStream());
dataOutputStream = new DataOutputStream(
socket.getOutputStream());
String messageFromClient = "";
//If no message sent from client, this code will block the program
messageFromClient = dataInputStream.readUTF();
I Split the Latitude and Longitude this way in the Server side
for(int j=0;j<i;j++){
if(messageFromClient.charAt(j)!='+' && bool==false){
s=s+messageFromClient.charAt(j);
}
else{
bool=true;
}
if(bool){
t=t+messageFromClient.charAt(j);
}
}
I Store in these two Variable
b = Double.parseDouble(s);
c = Double.parseDouble(t);
ToMain.this.runOnUiThread(new Runnable() {
@Override
public void run() {
}
});
String msgReply = "Location Sent!" + count;
dataOutputStream.writeUTF(msgReply);
i want to send those variable from here to the main activity which contain the map
// startActivity(intent);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
final String errMsg = e.toString();
ToMain.this.runOnUiThread(new Runnable() {
@Override
public void run() {
}
});
} finally {
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (dataInputStream != null) {
try {
dataInputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (dataOutputStream != null) {
try {
dataOutputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
How do i pass a and b to the main activity.