/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ // no package required or desired, use Netbeans menu item "Run File import java.io.*; import java.net.*; /** * * @author cs2017 */ public class AngelClient { /** * @param args the command line arguments */ public static void main(String[] args) { boolean operate = true; while (operate) { try { System.out.println("creating socket"); // We request an IP to connect to ("localhost") and // port number at that IP (2317). This establishes // a connection to that IP in the form of the Socket // object; the server uses a ServerSocket to wait for // connections. Socket socket = new Socket("localhost", 2317); // Read the single line written by the server. We'd // do things a bit differently if many lines to be read // from the server, instead of one only. InputStream is = socket.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String serverMessage = br.readLine(); if ("Exit".equals(serverMessage)){ System.out.println("The server has asked to shut the client down."); operate = false; } else { int spd = Integer.parseInt(br.readLine()); int x = Integer.parseInt(br.readLine()); int y = Integer.parseInt(br.readLine()); int z = Integer.parseInt(br.readLine()); String lastCommand = br.readLine(); AngelTank tank = new AngelTank(serverMessage, spd, new int[]{x, y, z}); System.out.println(serverMessage+" is traveling at "+spd+" with position ("+x+", "+y+", "+z+")."); if ("Exit".equals(lastCommand)){ System.out.println("The server has asked to shut the client down."); operate = false; } } } catch(IOException e) { System.out.println(e); System.out.println("Problem with client"); } } } }