2014. 6. 29. 16:55ㆍProgramming/Java
class ConnectThread extends Thread {
String sendMsg;
String return_msg;
public ConnectThread(String msg) {
sendMsg = msg;
}
public void run() {
try {
DatagramSocket socket = new DatagramSocket();
InetAddress serverAddr = InetAddress.getByName(ipAddr);
byte[] buf = new byte[256];
buf = sendMsg.getBytes();
DatagramPacket Packet = new DatagramPacket(buf, buf.length, serverAddr, port);
socket.send(Packet);
buf = new byte[256];
Packet = new DatagramPacket(buf, buf.length, serverAddr, port);
socket.receive(Packet);
return_msg = new String(Packet.getData());
sendMessage(return_msg);
} catch(Exception ex) {
ex.printStackTrace();
}
}
}
'Programming > Java' 카테고리의 다른 글
Java로 RaspberryPi GPIO 제어하기!(CODE section) (0) | 2014.07.20 |
---|---|
TCP<Client side> (0) | 2014.06.29 |
TCP<Server side> (0) | 2014.06.29 |
UDP<Server side> (0) | 2014.06.29 |
자신의 IP 알아내기 (0) | 2014.06.23 |