1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
public class TCP_Client extends AsyncTask {
 
    protected static String SERV_IP = "server ip"
    protected static int PORT = 0000;
 
    @Override
    protected Object doInBackground(Object... params) {
        // TODO Auto-generated method stub
 
        
        try {
            Socket sock = new Socket(SERV_IP, PORT);
            DataInputStream input = new DataInputStream(sock.getInputStream());
            DataOutputStream output = new DataOutputStream(sock.getOutputStream());
 
            
            try {
                
                WriteSocket(output);
//                ReadSock(input);
 
 
            } catch (IOException e) {
                e.printStackTrace();
            }
 
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
 
        return null;
    }
 
    public void WriteSocket(DataOutputStream data) throws IOException {
        // data send
        byte[] bData = new byte[2];
        
 
        bData[0= (byte0x00;
        bData[1= (byte0x00;
   
        
        data.write(bData);
    }
 
    public void ReadSock(DataInputStream data) throws IOException {
        // data recieve
        byte[] datafile = null;
 
        data.read(datafile);
 
    }
}
cs



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public class MainActivity extends Activity {
 
    private Button btn;
    TCP_Client tc;
 
    public void onCreate(Bundle savedInstanceState) {
 
        super.onCreate(savedInstanceState);
 
        setContentView(R.layout.activity_main);
 
        btn = (Button) findViewById(R.id.Button01);
        btn.setOnClickListener(new View.OnClickListener() {
 
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                tc = new TCP_Client();
                tc.execute(this);
            }
        });
 
    }
 
}
cs




'이것저것 > 자바*안드로이드' 카테고리의 다른 글

TabWidget 탭 이미지 변경  (0) 2016.11.28
xml 파싱  (0) 2016.11.24
TabHost  (0) 2016.11.09
TimePickerDialog  (0) 2016.11.08
Okhttp jar  (0) 2016.10.27

+ Recent posts