#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    1
    Rep Power
    0

    I need help from expert


    hai i want to know can i put camera on my server activity and my button capture is on my client activity and the image of capture will safe on client .. can help me out ?
    i use textfield is for to show that u already connected ...


    here the code for client activity
    import java.io.BufferedWriter;
    import java.io.IOException;
    import java.io.OutputStreamWriter;
    import java.io.PrintWriter;
    import java.net.InetAddress;
    import java.net.Socket;
    import java.net.UnknownHostException;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.EditText;

    public class Client extends Activity {

    private Socket socket;

    private static final int SERVERPORT = 5000;
    private static final String SERVER_IP = "10.0.2.2";

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    new Thread(new ClientThread()).start();
    }

    public void onClick(View view) {
    try {
    EditText et = (EditText) findViewById(R.id.EditText01);
    String str = et.getText().toString();
    PrintWriter out = new PrintWriter(new BufferedWriter(
    new OutputStreamWriter(socket.getOutputStream())),
    true);
    out.println(str);
    } catch (UnknownHostException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    class ClientThread implements Runnable {

    @Override
    public void run() {

    try {
    InetAddress serverAddr = InetAddress.getByName(SERVER_IP);

    socket = new Socket(serverAddr, SERVERPORT);

    } catch (UnknownHostException e1) {
    e1.printStackTrace();
    } catch (IOException e1) {
    e1.printStackTrace();
    }

    }

    }


    and this server actvity

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.ServerSocket;
    import java.net.Socket;

    import android.app.Activity;
    import android.os.Bundle;
    import android.os.Handler;
    import android.widget.TextView;

    public class Server extends Activity {

    private ServerSocket serverSocket;

    Handler updateConversationHandler;

    Thread serverThread = null;

    private TextView text;



    public static final int SERVERPORT = 6000;

    @Override
    public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    text = (TextView) findViewById(R.id.text2);

    updateConversationHandler = new Handler();

    this.serverThread = new Thread(new ServerThread());
    this.serverThread.start();

    }

    @Override
    protected void onStop() {
    super.onStop();
    try {
    serverSocket.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    class ServerThread implements Runnable {

    public void run() {
    Socket socket = null;
    try {
    serverSocket = new ServerSocket(SERVERPORT);
    } catch (IOException e) {
    e.printStackTrace();
    }
    while (!Thread.currentThread().isInterrupted()) {

    try {

    socket = serverSocket.accept();

    CommunicationThread commThread = new CommunicationThread(socket);
    new Thread(commThread).start();

    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }
    }

    class CommunicationThread implements Runnable {

    private Socket clientSocket;

    private BufferedReader input;

    public CommunicationThread(Socket clientSocket) {

    this.clientSocket = clientSocket;

    try {

    this.input = new BufferedReader(new InputStreamReader(this.clientSocket.getInputStream()));

    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    public void run() {


    while (!Thread.currentThread().isInterrupted()) {

    try {

    String read = input.readLine();

    updateConversationHandler.post(new updateUIThread(read));

    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }

    }

    class updateUIThread implements Runnable {
    private String msg;

    public updateUIThread(String str) {
    this.msg = str;
    }

    @Override
    public void run() {
    text.setText(text.getText().toString()+"Client Says: "+ msg + "\n");
    }

    }

    }


    can help me out
    Last edited by faizalalif; September 1st, 2013 at 09:41 PM. Reason: error
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Location
    usa
    Posts
    2
    Rep Power
    0
    h hope any person here in the forum to help u cause i have the same issue too

IMN logo majestic logo threadwatch logo seochat tools logo