I have this client and multi threaded server and need to do an end of file and an acknowledgement but it wont seem to work because of the errors can anyone help me plsss ?
import java.io.*; import java.net.*; class NetworkFileClient1 { public static void main(String args[]) throws IOException { DatagramSocket socket = new DatagramSocket(2019); //setting up port number to communicate with server socket.setSoTimeout(1000); boolean received = false; String message = new String("HELO\r\n"); DatagramPacket packet = new DatagramPacket( message.getBytes(), message.length(), InetAddress.getByName("127.0.0.1"), 87); //Show how server was found by using getByName method. //Int address Returns the IP address of the machine from which the datagram was received or sent.(of the server) socket.send(packet); System.out.println("Request sent!"); //when client get the server destination details by the getname method it will send a request to server byte buffer[] = new byte[1090000]; boolean receiving = true; PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("CopyofTextfile.txt"))); // check while (receiving) { //when request is sent to server the client will display a . while receiving the datagram try { DatagramPacket getbitoffile = new DatagramPacket(buffer, buffer.length); socket.receive(getbitoffile); buffer = getbitoffile.getData(); //returns the data buffer if (!(lineFromServer.equals("***EOF***"))) { pw.println(getbitoffile); // Writing lines being received to text file System.out.print("."); lineFromServer = new String(receivePacket.getData(), 0, receivePacket.getLength()); } if (lineFromServer.equals("***EOF***"))) { receiving = false; System.out.println("File Received..."); pw.close; } catch (SocketTimeoutException e) { //if data is not received until timeout exception program will display("") receiving = false; System.out.println("Timeout. Got fed up waiting..."); } } } }
//Server import java.net.*; import java.io.*; //client class Worker implements Runnable { DatagramSocket socket = null; DatagramPacket packet = null; public Worker (DatagramSocket socket, DatagramPacket packet) { this.socket = socket; this.packet = packet; } public void run() { try { BufferedReader fileCopyBuffer = new BufferedReader(new InputStreamReader(new FileInputStream ("NormanConquest.txt"))); String strFromClient; String line; while ((line = fileCopyBuffer.readLine()) != null) { DatagramPacket response = new DatagramPacket(line.getBytes(), line.length(),packet.getAddress() , packet.getPort()); System.out.print("."); socket.send(response); strLine = "***EOF***"; buf = strLine.getBytes(); odp = new DatagramPacket(buf, buf.length, idp.getAddress(), idp.getPort()); ds.send(odp); System.out.println("File transfer is complete!"); } } catch (Exception e){;}; // might consider saving in text file } } class Server { public static void main(String Args[]){ try {DatagramSocket socket = new DatagramSocket(87); while (true) { byte buffer[] = new byte[66508]; DatagramPacket getstartpacket = new DatagramPacket(buffer, buffer.length); socket.receive(getstartpacket); new Thread( new Worker(socket, getstartpacket)).start(); } } catch (Exception e) {;}; } }
These are errors given to me by the server when compiled
Server.java:30: error: cannot find symbol
strLine = "***EOF***";
^
symbol: variable strLine
location: class Worker
Server.java:31: error: cannot find symbol
buf = strLine.getBytes();
^
symbol: variable buf
location: class Worker
Server.java:31: error: cannot find symbol
buf = strLine.getBytes();
^
symbol: variable strLine
location: class Worker
Server.java:32: error: cannot find symbol
odp = new DatagramPacket(buf, buf.length, idp.getAddress(), idp.getPort());
^
symbol: variable odp
location: class Worker
Server.java:32: error: cannot find symbol
odp = new DatagramPacket(buf, buf.length, idp.getAddress(), idp.getPort());
^
symbol: variable buf
location: class Worker
Server.java:32: error: cannot find symbol
odp = new DatagramPacket(buf, buf.length, idp.getAddress(), idp.getPort());
^
symbol: variable buf
location: class Worker
Server.java:32: error: cannot find symbol
odp = new DatagramPacket(buf, buf.length, idp.getAddress(), idp.getPort());
^
symbol: variable idp
location: class Worker
Server.java:32: error: cannot find symbol
odp = new DatagramPacket(buf, buf.length, idp.getAddress(), idp.getPort());
^
symbol: variable idp
location: class Worker
Server.java:33: error: cannot find symbol
ds.send(odp);
^
symbol: variable odp
location: class Worker
Server.java:33: error: cannot find symbol
ds.send(odp);
^
symbol: variable ds
location: class Worker
10 errors
Tool completed with exit code 1
And these are those of the client
NetworkFileClient1.java:46: error: illegal start of expression
if (lineFromServer.equals("***EOF***"))) {
^
NetworkFileClient1.java:50: error: not a statement
pw.close;
^
NetworkFileClient1.java:53: error: 'catch' without 'try'
catch (SocketTimeoutException e) { //if data is not received until timeout exception program will display("")
^
NetworkFileClient1.java:53: error: ')' expected
catch (SocketTimeoutException e) { //if data is not received until timeout exception program will display("")
^
NetworkFileClient1.java:53: error: not a statement
catch (SocketTimeoutException e) { //if data is not received until timeout exception program will display("")
^
NetworkFileClient1.java:53: error: ';' expected
catch (SocketTimeoutException e) { //if data is not received until timeout exception program will display("")
^
NetworkFileClient1.java:28: error: 'try' without 'catch', 'finally' or resource declarations
try {
^
NetworkFileClient1.java:61: error: reached end of file while parsing
}
^
8 errors
Tool completed with exit code 1