package sample;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Date;

public class tcp_client {

	public static void main(String[] args) throws IOException, Throwable {
		// TODO ꂽ\bhEX^u
		String server = "61.192.170.190";
		int servPort = 5000;
		// byte[] data = "Hello, Net world".getBytes();
		byte[] data = { 0x4d, 0x45, 0x4c, 0x53, 0x00, 0x01, 0x04, 0x08, 0x00,
				0x1e, (byte) 0x86, 0x11, 0x11, 0x11, 0x13, 0x43, 0x01, 0x01,
				0x07, 0x00, 0x00, 0x00, 0x00, 0x00,1,77,69 };
		byte[] msg = new byte[data.length];

		Socket socket = new Socket(server, servPort);
		System.out.println("T[oƂ̐ڑmB");

		InputStream in = socket.getInputStream();
		OutputStream out = socket.getOutputStream();

		out.write(data); // T[oɕ𑗕t
		while (true) {
			System.out.println("MF" + new String(data));
			System.out.println("main startF" + new Date());
			// Timer.schedule(task, TimeUnit.SECONDS.toMillis(10)); // 10bɎs
			out.write(data); // T[oɕ𑗕t
			sleep(100);

			// T[o̕ԐMM
			int totalBytesRcvd = 0;
			int bytesRcvd;
			// while (totalBytesRcvd < data.length) { // SM܂loop
			// if ((bytesRcvd = in.read( // ͓Ǎf[^AOffsetAǍf[^
			// msg, totalBytesRcvd, data.length - totalBytesRcvd)) == -1) {
			// throw new SocketException("ڑՒf");
			// }
			// totalBytesRcvd += bytesRcvd;
			// } // while end
			// System.out.println("MF" + new String(msg));

			socket.close();
		}
	}

	public static void sleep(long millis) throws InterruptedException {

		try {
			Thread.sleep(3000); // 3000~bSleep
		} catch (InterruptedException e) {
		}

	}
}
