티스토리 뷰
package pkg.MinPos;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
public class UdpClient {
private int m_Port;
private String m_Host;
private DatagramSocket m_Ds;
private InetAddress m_Ia;
private DatagramPacket m_DpSend, m_DpRcv;
UdpClient(String Host, int Port) {
m_Host = Host;
m_Port = Port;
}
public boolean connServer() {
try {
m_Ds = new DatagramSocket(m_Port);
m_Ia = InetAddress.getByName(m_Host);
} catch(IOException e) {
return false;
}
return true;
}
public boolean sendData(String Msg) {
try {
m_DpSend = new DatagramPacket(Msg.getBytes(), Msg.getBytes().length, m_Ia, m_Port);
m_Ds.send(m_DpSend);
} catch(IOException e) {
return false;
}
return true;
}
public String rcvData() {
String Msg;
byte[] data = new byte[1024];
try {
m_DpRcv = new DatagramPacket(data, data.length);
m_Ds.receive(m_DpRcv);
Msg = new String(m_DpRcv.getData(), 0, m_DpRcv.getData().length);
} catch(IOException e) {
Msg = "";
}
return Msg;
}
public void closeServer() {
m_Ds.close();
}
}
'Android > Java' 카테고리의 다른 글
CharAt(), substring(), indexOf(), length() (0) | 2019.03.20 |
---|---|
문자열이 있는지 확인 (0) | 2019.03.20 |
문자열을 정수, 실수로 (0) | 2019.03.20 |
정수, 실수를 문자열로 (0) | 2019.03.20 |
Thread.sleep (0) | 2019.03.20 |
- Total
- Today
- Yesterday