I have the following code and have to fill in the blanks can u help at all? i'm trying to connect a client to a server using TCP layout, any help at all would be GREATLY appreciated! Thanks!
import java.io.*; import java.net.*;
public class P2_3_Client { static void process() { try { BufferedReader user_input = new BufferedReader(new InputStreamReader(System.in));
// create a socket ....
// get input & output streams .... ....
// read and print to screen a message from server System.out.println(....);
boolean hit = false; int row = 0, column = 0; String from_keyboard;
/* when an array of type String is allocated it's elements are automatically set to null */ String[][] grid = new String[4][4]; drawGrid(grid);
// get indication of hit or miss from server hit = .... if (hit) { System.out.println("HIT!"); grid[row][column] = "h"; } else { System.out.println("MISS"); grid[row][column] = "m"; } drawGrid(grid); } while(!hit);
public class P2_3_Server { public P2_3_Server() { try { ServerSocket .... System.out.println("P2_3_Server is up and waiting for a connection..."); getClients(....); } catch (IOException e) { System.out.println(e); System.exit(1); } }
// connection request received and processed, get input & output streams .... ....
// generate random choice for battleship position int battleship_row = (int) (Math.random() * 4); int battleship_column = (int) (Math.random() * 4); boolean hit = false; int user_row, user_column;
// send acknowledgement of request service to client ....("Connection to " + (InetAddress.getLocalHost()).getHostName() + " is successful");
while (!hit) { .... .... if (.... == battleship_row && .... == battleship_column) hit = true; ....(hit); }