티스토리 뷰
// TCP Client
private Socket socket = null
private BufferedInputStream bis;
private BufferedOutputStream bos;
// Socket TCP
public boolean TcpServerConnect(String host, int port) {
try {
socket = new Socket(InetAddress.getByName(host), port);
bis = new BufferedInputStream(socket.getInputStream());
bos = new BufferedOutputStream(socket.getOutputStream());
}
catch(IOException e) {
return false;
}
return true;
}
public boolean TcpSendMsg(String message) {
try {
bos.write(message.getBytes());
bos.flush();
}
catch(IOException e) {
return false;
}
return true;
}
public String TcpRcvMsg() throws IOException {
byte[] buf = new byte[BUFSIZE];
String RcvBuff;
bis.read(buf);
RcvBuff = new String(buf);
return RcvBuff;
}
public void TcpDisconnect() throws IOException {
try {
socket.shutdownOutput();
socket.shutdownInput();
socket.close();
bis.close();
bos.close();
}
catch(IOException e) {
return;
}
}
'Android > Java' 카테고리의 다른 글
날짜 계산 (0) | 2019.03.20 |
---|---|
한 라인 밑으로 (0) | 2019.03.20 |
String Class (0) | 2019.03.20 |
문자열에서 문자열 찾기 (0) | 2019.03.20 |
파일 삭제 (0) | 2019.03.20 |
- Total
- Today
- Yesterday