UDP(2)
-
UDP<Client side>
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(P..
2014.06.29 -
UDP<Server side>
static DatagramSocket socket;static DatagramPacket receivePacket;socket = new DatagramSocket(8080); while(true){byte[] buf = new byte[256]; //byte를 선언 합니다.receivePacket = new DatagramPacket(buf, buf.length); socket.receive(receivePacket);String msg = new String(receivePacket.getData(), 0, receivePacket.getLength());msg = new String(msg.getBytes("8859_1"), "KSC5601");//Client로 다시 전송합니다.receivePac..
2014.06.29