SOCKET(4)
-
TCP<Client side>
class ConnectThread extends Thread { String sendMsg; public ConnectThread(String msg) { sendMsg = msg; } public void run() { try { Socket sock = new Socket(ipAddr, port); ObjectOutputStream outstream = new ObjectOutputStream(sock.getOutputStream()); outstream.writeObject(sendMsg); outstream.flush(); sock.close(); } catch(Exception ex) { ex.printStackTrace(); } } }
2014.06.29 -
TCP<Server side>
class outputThread extends Thread {Socket aSocket;ServerFrame serverFrame; public outputThread(Socket sock, ServerFrame sf) { aSocket = sock; serverFrame = sf; } public void run() { try { ObjectInputStream instream = new ObjectInputStream(aSocket.getInputStream());Object obj = instream.readObject();serverFrame.area.append("Input : " + obj+"\n");aSocket.close(); } catch(Exception ex) { ex.printSt..
2014.06.29 -
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