티스토리 뷰
반응형
package pkg.프로그램명;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
public class TCPClient {
private Socket m_socket = null;
private BufferedInputStream m_bis;
private BufferedOutputStream m_bos;
private final int BUFF_SIZE = 1024;
public boolean Connect(String host, int port) {
try {
m_socket = new Socket(InetAddress.getByName(host), port);
m_bis = new BufferedInputStream(m_socket.getInputStream());
m_bos = new BufferedOutputStream(m_socket.getOutputStream());
}
catch(IOException e) {
return false;
}
return true;
}
public boolean SendMsg(String SendBuff) {
try {
m_bos.write(SendBuff.getBytes());
m_bos.flush();
}
catch(IOException e) {
return false;
}
return true;
}
public String RcvMsg() throws IOException {
byte[] buf = new byte[BUFF_SIZE];
String RcvBuff;
m_bis.read(buf);
RcvBuff = new String(buf);
return RcvBuff;
}
public void Disconnect() throws IOException {
try {
m_socket.shutdownOutput();
m_socket.shutdownInput();
m_socket.close();
m_bis.close();
m_bos.close();
}
catch(IOException e) {
return;
}
}
}
반응형
'Android > Java' 카테고리의 다른 글
파일 삭제 (0) | 2019.03.20 |
---|---|
파일 쓰기 (0) | 2019.03.20 |
char[] to String 변환 (0) | 2019.03.20 |
리눅스 서버와 TCP 통신시 한글 인코딩 (0) | 2019.03.20 |
자바 기본 인코딩 확인하는 함수 (0) | 2019.03.20 |
댓글
반응형
최근에 올라온 글
- Total
- Today
- Yesterday