import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
public class Port42001 {
public static void main(String[] args) {
String ip = "127.0.0.1";
int port = 42001;
try {
Socket socket = new Socket(ip, port);
PrintStream out = new PrintStream(socket.getOutputStream());
BufferedReader systemin = new BufferedReader(new InputStreamReader(
System.in));
String line;
System.out.println("'q' is 'quit'.");
while (true) {
System.out.print(">");
line = systemin.readLine();
sendtoscratch(out, "sensor-update \"Scratch-Value0\" " + line);
if (line.equals("q")) {
break;
}
}
systemin.close();
out.close();
socket.close();
} catch (IOException e) {
System.out.println("Can not connect to the server (" + ip + ") .");
System.exit(1);
}
}
static void sendtoscratch(PrintStream out, String dataOut) {
byte[] sizeBytes = { 0, 0, 0, 0 };
sizeBytes[3] = (byte) (dataOut.length());
for (int i = 0; i < 4; i++) {
out.write(sizeBytes[i]);
}
out.print(dataOut);
}
}
0 件のコメント:
コメントを投稿