Created
July 18, 2012 06:58
-
-
Save kimkidong/3134697 to your computer and use it in GitHub Desktop.
안드로이드 클라이언트 소켓2(ver.test)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.client_test; | |
import java.io.DataInputStream; | |
import java.io.DataOutputStream; | |
import java.io.IOException; | |
import java.net.InetAddress; | |
import java.net.Socket; | |
import java.net.UnknownHostException; | |
import android.os.AsyncTask; | |
import android.util.Log; | |
public class TCP_Client extends AsyncTask{ | |
protected static String SERV_IP = "xxx.xxx.xxx.xxx"; //server ip | |
protected static int PORT = 8001; | |
@Override | |
protected Object doInBackground(Object... params) { | |
// TODO Auto-generated method stub | |
try { | |
Log.d("TCP","server connecting"); | |
InetAddress serverAddr = InetAddress.getByName(SERV_IP); | |
Socket sock = new Socket(serverAddr,PORT); | |
DataInputStream input = new DataInputStream(sock.getInputStream()); | |
DataOutputStream output = new DataOutputStream(sock.getOutputStream()); | |
try{ | |
// 데이터 송신 부분! | |
WriteSocket(output); | |
} catch(IOException e){ | |
Log.e("TCP","don't send message!"); | |
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 | |
data.write('a'); | |
} | |
public void ReadSock(DataInputStream data) throws IOException{ | |
// data recieve | |
byte[] datafile = null; | |
data.read(datafile); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment