Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package androidChatClient.src;
- import java.io.IOException;
- import java.net.InetAddress;
- import java.net.Socket;
- import android.app.Activity;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.text.Editable;
- import android.view.View;
- import android.widget.*;
- public class Main extends Activity {
- Socket socket;
- private EditText _output;
- private EditText _input;
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- String ip = "192.168.1.3";
- _output = (EditText)findViewById(R.id.output);
- try {
- _output.append("Connecting to..."+ip+"\n");
- InetAddress ia = InetAddress.getByName(ip);
- socket = new Socket(ia, 7777);
- _output.append("Connected\n");
- socket.getOutputStream().write(new String(InetAddress.getLocalHost().getHostAddress()+" joined.").getBytes());
- } catch (Exception e) {
- // TODO Auto-generated catch block
- System.out.println("Client:" + e);
- e.printStackTrace();
- }
- class ListenTask extends AsyncTask<Void, String, Void>{
- protected Void doInBackground(Void... args) {
- boolean run = true;
- while(run){
- return null;
- }
- }
- }
- public void exit(View view){
- try{
- socket.getOutputStream().write(new String(InetAddress.getLocalHost().getHostAddress()+" left.").getBytes());
- socket.close();
- System.exit(0);
- }catch (Exception e){
- }
- }
- public void send(View view){
- Editable textTemp;
- _input = (EditText)findViewById(R.id.input);
- textTemp = _input.getText();
- String text = textTemp.toString();
- try {
- socket.getOutputStream().write(new String(text).getBytes());
- } catch (IOException e) {
- e.printStackTrace();
- }
- _input.setText("");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement